-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't pollute docs/suggestions with libstd deps #73771
Conversation
Currently dependency crates of the standard library can sometimes leak into error messages such as when traits to import are suggested. Additionally they can leak into documentation such as in the list of "all traits implemented by `u32`". The dependencies of the standard library, however, are intended to be private. The dependencies of the standard library can't actually be stabl-y imported nor is the documentation that relevant since you can't import them on stable either. This commit updates both the compiler and rustdoc to ignore unstable traits in these two scenarios. Specifically the suggestion for traits to import ignore unstable traits, and similarly the list of traits implemented by a type excludes unstable traits. This commit is extracted from rust-lang#73441 where the addition of some new dependencies to the standard library was showed to leak into various error messages and documentation. The intention here is to go ahead and land these changes ahead of that since it will likely take some time to land.
(rust_highfive has picked a reviewer for you, use r? to override) |
r? @estebank |
// example, from getting documented as "traits `u32` implements" which | ||
// isn't really too helpful. | ||
if let Some(stab) = cx.tcx.lookup_stability(did) { | ||
if stab.level.is_unstable() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't you want to filter them out only on non-nightly builds?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so because that still creates the same issues seen on #73441 where it causes broken links to appear in libstd's nightly documentation because libstd's internal dependencies aren't documented.
@bors try I would like to make sure that this doesn't affect the published rustc docs -- all of those are currently marked unstable, but we do indeed want to display e.g. the HashStable impl on the Symbol page: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/symbol/struct.Symbol.html#impl-HashStable%3CCTX%3E I think the current state of this PR will not do so; it might be preferable to limit the exclusion to apply to just std + core + alloc perhaps. I'm not sure if that's the best approach, though. Maybe we should be (for example) annotating these dependencies with |
⌛ Trying commit fde8d11 with merge 9ffb7801363cff45dcb56fa2146a48aa0ae433db... |
☀️ Try build successful - checks-actions, checks-azure |
The intention here, to clarify, is that there are crates whose source code we do not control (e.g. The intention here is that libstd would get all its documentation, although rustc is a good point I forgot to consider. Again to clarify though the heuristic isn't to avoid documenting things, it's just to skip listing foreign unstable traits under "traits implemented" in rustdoc (otherwise broken links are generated). Checking the rustc docs there's lots of impls and such for I do suspect that docs are lacking in a way I'm missing though. One example I've found is that If this is crucial to keep implemented I could try and add some sort of check where only |
Yeah, I think keeping Try in docs is probably pretty important -- I'm not too worried about rustc docs, I think, but std docs missing public traits is pretty unfortunate. I don't have any strong feelings on this though, and I do think the backtrace work is probably more important than figuring this out, I'd personally be fine landing this as-is (even with the slight regressions) -- realistically, unstable traits aren't that important. We can also "fix" the rustc case by avoiding passing -Zforce-unstable-if-unmarked or w/e the flag is when documenting rustc, I think. |
rustdoc has a |
@ollie27 this is a problem not only for direct dependencies but also transitive dependencies of the standard library. For example libstd does not actually depend directly on |
r=me on the diagnostic affecting changes, but feel free to continue the conversation around rustdoc |
Is there any reason |
At this point it's already hard enough to add dependencies to the standard library and this is a hidden gotcha that seems very difficult to remember. I would much rather have a systematic solution that fixes the problem for all dependencies instead of just one at a time as it just so happens to be an issue. The list of crates that this needs to apply to are:
This isn't just a trivial list of dependencies, and this list is going to be difficult to manage over time. I'm not sure why we'd want to put ourselves through those paces rather than just fixing this once. |
I am actually fairly surprised that rustdoc is listing trait impls for dependencies of std. Maybe it would be sufficient to just not document gimli etc (instead only a specific list, probably core/std/alloc only) in bootstrap? |
The gimli crate is not documented, the problem is that rustdoc is listing Showing All that basically to say that gimli is already not documented. This'd probably actually be fixed if it were since the link would be generated correctly. |
Huh, so rustdoc is finding out about the trait impl some other way. I am personally inclined to land the PR in its current form -- we do lose Try impls and (presumably) some others like SliceConcatExt and so forth, but that seems largely fine. I also don't think we have a good handle on an "excellent" fix beyond the one this PR takes on. In the long term, I suppose that rustdoc would receive information from Cargo about public/private dependencies and based on that show (or not show) trait impls on types. |
One option would be to invert Another option would be to tell rustdoc to hide anything from crates it can't generate local relative links to when documenting Long term I wonder if #44663 could be used to resolve this. I guess we can merge this temporarily if it helps unblock things though.
That's very much a rustdoc bug, I've filed #74222. |
FWIW these all do indeed sound like other alternatives to this, although they do all seem like more work than this local fix. This'll be required for #73441 but that's still waiting on review so it's not necessarily super urgent to fix this now but I suspect #73441 will be ready in the near-ish future. |
So to clarify, it this still waiting for someone to take a look? Is it expected that I'm to take action and implement a different strategy other than this PR? |
I believe either @GuillaumeGomez or @ollie27 need to decide whether they're okay with landing this patch as-is (@estebank has approved the diagnostics changes). I myself am fine with it as is, if not super happy, but I think it's good enough. I don't feel comfortable approving if there's outstanding objections on their ends though. |
I guess this is an acceptable fix for the meantime but please open an issue so we can write a full one later on. So unless @ollie27 has objections, r=me. |
@ollie27 could you weigh in on the latest comments? |
If this is holding up other work and people are okay with the docs regression especially with the compiler docs then I'm not going to block this. @bors r=estebank,GuillaumeGomez |
📌 Commit fde8d11 has been approved by |
…ebank,GuillaumeGomez Don't pollute docs/suggestions with libstd deps Currently dependency crates of the standard library can sometimes leak into error messages such as when traits to import are suggested. Additionally they can leak into documentation such as in the list of "all traits implemented by `u32`". The dependencies of the standard library, however, are intended to be private. The dependencies of the standard library can't actually be stabl-y imported nor is the documentation that relevant since you can't import them on stable either. This commit updates both the compiler and rustdoc to ignore unstable traits in these two scenarios. Specifically the suggestion for traits to import ignore unstable traits, and similarly the list of traits implemented by a type excludes unstable traits. This commit is extracted from rust-lang#73441 where the addition of some new dependencies to the standard library was showed to leak into various error messages and documentation. The intention here is to go ahead and land these changes ahead of that since it will likely take some time to land.
…ebank,GuillaumeGomez Don't pollute docs/suggestions with libstd deps Currently dependency crates of the standard library can sometimes leak into error messages such as when traits to import are suggested. Additionally they can leak into documentation such as in the list of "all traits implemented by `u32`". The dependencies of the standard library, however, are intended to be private. The dependencies of the standard library can't actually be stabl-y imported nor is the documentation that relevant since you can't import them on stable either. This commit updates both the compiler and rustdoc to ignore unstable traits in these two scenarios. Specifically the suggestion for traits to import ignore unstable traits, and similarly the list of traits implemented by a type excludes unstable traits. This commit is extracted from rust-lang#73441 where the addition of some new dependencies to the standard library was showed to leak into various error messages and documentation. The intention here is to go ahead and land these changes ahead of that since it will likely take some time to land.
…ebank,GuillaumeGomez Don't pollute docs/suggestions with libstd deps Currently dependency crates of the standard library can sometimes leak into error messages such as when traits to import are suggested. Additionally they can leak into documentation such as in the list of "all traits implemented by `u32`". The dependencies of the standard library, however, are intended to be private. The dependencies of the standard library can't actually be stabl-y imported nor is the documentation that relevant since you can't import them on stable either. This commit updates both the compiler and rustdoc to ignore unstable traits in these two scenarios. Specifically the suggestion for traits to import ignore unstable traits, and similarly the list of traits implemented by a type excludes unstable traits. This commit is extracted from rust-lang#73441 where the addition of some new dependencies to the standard library was showed to leak into various error messages and documentation. The intention here is to go ahead and land these changes ahead of that since it will likely take some time to land.
…arth Rollup of 21 pull requests Successful merges: - rust-lang#73566 (Don't run `everybody_loops` for rustdoc; instead ignore resolution errors) - rust-lang#73771 (Don't pollute docs/suggestions with libstd deps) - rust-lang#73794 (Small cleanup for E0705 explanation) - rust-lang#73807 (rustdoc: glue tokens before highlighting) - rust-lang#73835 (Clean up E0710 explanation) - rust-lang#73926 (Ignoring test case: [codegen] repr-transparent-aggregates-1.rs for aarch64) - rust-lang#73981 (Remove some `ignore-stage1` annotations.) - rust-lang#73998 (add regression test for rust-lang#61216) - rust-lang#74140 (Make hir ProjectionKind more precise) - rust-lang#74148 (Move #[doc(alias)] check in rustc) - rust-lang#74159 (forbid generic params in the type of const params) - rust-lang#74171 (Fix 44056 test with debug on macos.) - rust-lang#74221 (Don't panic if the lhs of a div by zero is not statically known) - rust-lang#74325 (Focus on the current file in the source file sidebar) - rust-lang#74359 (rustdoc: Rename internal API fns to `into_string`) - rust-lang#74370 (Reintroduce spotlight / "important traits" feature) - rust-lang#74390 (Fix typo in std::mem::transmute documentation) - rust-lang#74391 (BtreeMap: superficially refactor root access) - rust-lang#74392 (const generics triage) - rust-lang#74397 (Fix typo in the latest release note) - rust-lang#74406 (Set shell for github actions CI) Failed merges: r? @ghost
Note: this caused a regression, see #74531 |
Currently dependency crates of the standard library can sometimes leak
into error messages such as when traits to import are suggested.
Additionally they can leak into documentation such as in the list of
"all traits implemented by
u32
". The dependencies of the standardlibrary, however, are intended to be private.
The dependencies of the standard library can't actually be stabl-y
imported nor is the documentation that relevant since you can't import
them on stable either. This commit updates both the compiler and rustdoc
to ignore unstable traits in these two scenarios.
Specifically the suggestion for traits to import ignore unstable traits,
and similarly the list of traits implemented by a type excludes unstable
traits.
This commit is extracted from #73441 where the addition of some new
dependencies to the standard library was showed to leak into various
error messages and documentation. The intention here is to go ahead and
land these changes ahead of that since it will likely take some time to
land.