Skip to content

Commit 2254f3c

Browse files
Merge pull request #2406 from jyn514/rustdoc-bodies
document why rustdoc cannot look at function bodies
2 parents 8392ed6 + b9f639a commit 2254f3c

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/rustdoc.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,28 @@ Certain browser features that require secure origins, like `localStorage` and
116116
Service Workers, don't work reliably. We can still use such features but we
117117
should make sure pages are still usable without them.
118118

119+
Rustdoc [does not type-check function bodies][platform-specific docs].
120+
This works by [overriding the built-in queries for typeck][override queries],
121+
by [silencing name resolution errors], and by [not resolving opaque types].
122+
This comes with several caveats: in particular, rustdoc *cannot* run any parts of the compiler that
123+
require type-checking bodies; for example it cannot generate `.rlib` files or run most lints.
124+
We want to move away from this model eventually, but we need some alternative for
125+
[the people using it][async-std]; see [various][zulip stop accepting broken code]
126+
[previous][rustdoc meeting 2024-07-08] [zulip][compiler meeting 2023-01-26] [discussion][notriddle rfc].
127+
For examples of code that breaks if this hack is removed, see
128+
[`tests/rustdoc-ui/error-in-impl-trait`].
129+
130+
[platform-specific docs]: https://doc.rust-lang.org/rustdoc/advanced-features.html#interactions-between-platform-specific-docs
131+
[override queries]: https://github.com/rust-lang/rust/blob/52bf0cf795dfecc8b929ebb1c1e2545c3f41d4c9/src/librustdoc/core.rs#L299-L323
132+
[silencing name resolution errors]: https://github.com/rust-lang/rust/blob/52bf0cf795dfecc8b929ebb1c1e2545c3f41d4c9/compiler/rustc_resolve/src/late.rs#L4517
133+
[not resolving opaque types]: https://github.com/rust-lang/rust/blob/52bf0cf795dfecc8b929ebb1c1e2545c3f41d4c9/compiler/rustc_hir_analysis/src/check/check.rs#L188-L194
134+
[async-std]: https://github.com/rust-lang/rust/issues/75100
135+
[rustdoc meeting 2024-07-08]: https://rust-lang.zulipchat.com/#narrow/channel/393423-t-rustdoc.2Fmeetings/topic/meeting.202024-07-08/near/449969836
136+
[compiler meeting 2023-01-26]: https://rust-lang.zulipchat.com/#narrow/channel/238009-t-compiler.2Fmeetings/topic/.5Bweekly.5D.202023-01-26/near/323755789
137+
[zulip stop accepting broken code]: https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/stop.20accepting.20broken.20code
138+
[notriddle rfc]: https://rust-lang.zulipchat.com/#narrow/channel/266220-t-rustdoc/topic/Pre-RFC.3A.20stop.20accepting.20broken.20code
139+
[`tests/rustdoc-ui/error-in-impl-trait`]: https://github.com/rust-lang/rust/tree/163cb4ea3f0ae3bc7921cc259a08a7bf92e73ee6/tests/rustdoc-ui/error-in-impl-trait
140+
119141
## Multiple runs, same output directory
120142

121143
Rustdoc can be run multiple times for varying inputs, with its output set to the

0 commit comments

Comments
 (0)