-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Unify behaviours for re-exports of #[doc(hidden)]
#109697
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Unify behaviours for re-exports of #[doc(hidden)]
#109697
Conversation
This comment has been minimized.
This comment has been minimized.
18a298a
to
cf5b57e
Compare
Fixed tidy error. |
This comment has been minimized.
This comment has been minimized.
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
Two traits that are exported and didn't appear into the documentation before just did with this change. They were referencing to another item which doesn't appear into documentation so I added |
|
I'll merge this PR with #109456 then. |
Added the documentation so let's start the FCP. @rfcbot fcp merge |
Team member @GuillaumeGomez has proposed to merge this. The next step is review by the rest of the tagged team members: Concerns:
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
This comment has been minimized.
This comment has been minimized.
e6bd3f7
to
efff21a
Compare
Fixed tidy error in the rustdoc book. |
@rfcbot concern document-globs
I don't see this mentioned in the book (which claims that Assuming I understand this correctly, this means glob imports and explicit imports act differently in the face of doc(hidden), as described in this sample: pub mod outer {
mod inner {
#[doc(hidden)] struct FooBar;
struct FooBaz;
}
/// FooBar will be inlined here, because it's explicitly named.
pub use inner::FooBar;
/// FooBaz, of course, will also be inlined here.
pub use inner::FooBaz;
}
/// FooBar *WON'T* be inlined here, because it's #[doc(hidden)]
/// However, FooBaz will be inlined here, because it's just private.
pub use outer::inner::*; I get the reasoning behind it, but it's really weird, and needs to be documented. |
efff21a
to
907d77f
Compare
☔ The latest upstream changes (presumably #109500) made this pull request unmergeable. Please resolve the merge conflicts. |
@rfcbot resolve document-globs |
907d77f
to
ff65872
Compare
☔ The latest upstream changes (presumably #110481) made this pull request unmergeable. Please resolve the merge conflicts. |
6cc24fe
to
84ce917
Compare
Fixed merge conflict. |
edf4ee3
to
e1b3f41
Compare
The situation in mod m {
pub struct Foo;
pub type Bar = Foo;
#[doc(hidden)]
pub const Bar: Foo = Foo;
}
pub use m::Bar;
It doesn't in my tests. This is what we would ideally have in gimli: /// Little endian byte order.
pub struct LittleEndian;
/// The native endianity for the target platform.
#[cfg(target_endian = "little")]
pub use LittleEndian as NativeEndian; but when I test that, the documentation on the use statement is ignored. |
Ah right, I forgot about const/type alias case. As for the documentation for re-exports, it's only used when the re-exported item is inlined (whether by using |
This is also a concern from other angles, like semver. I don't think it can be forbidden directly due to backcompat and other reasons, but I've proposed that rustc lint it at the very least: Having the same names multiple times in the same namespace can have surprising downstream impacts, like causing adding an import a to be major breaking change. I wrote up some of these cases on my blog: https://predr.ag/blog/breaking-semver-in-rust-by-adding-private-type-or-import/ |
A new edition is coming up next year so we could turn it into an error. |
If we want to edition it we need to add a way of explicitly saying "no, I meant to reexport it publicly here" since the migration path needs to be designed. Just lint allows do not cut it for edition migrations. I recommend designing that mechanism, making it a lint, and having an edition migration for it that makes it hidden by default. We can then make it a hard error in the next edition, and eventually remove the error and switch the behavior if we want. |
Here's a few other things that seems kinda weird, that probably shouldn't work this way: #![crate_name = "foo"]
mod alpha {
#[doc(hidden)]
pub struct Alpha;
}
mod beta {
pub use crate::alpha::*;
}
// This is what it currently does.
// Is it what we want?
// @has foo/struct.Alpha.html
pub use beta::Alpha; This seems like a bug. The reason is that it implies that this should happen, which is definitely not what diesel wants: #![crate_name = "foo"]
mod alpha {
pub struct Alpha;
pub type Beta = Alpha;
#[doc(hidden)]
#[allow(nonstandard_style)]
pub const Beta: Beta = Alpha;
}
mod beta {
pub use crate::alpha::*;
}
// This is definitely correct.
// @has foo/struct.Alpha.html
// This is also correct.
// @has foo/type.Beta.html
// This probably isn't what we want. But it's the same thing as the first example!
// @has foo/constant.Beta.html
pub use beta::{Alpha, Beta}; |
It seems like more discussions are required. I think we could go by this simple rule: if any item has mod foo {
/// a
pub struct Bar;
}
mod bar {
/// b
#[doc(hidden)]
pub use crate::foo::Bar;
}
pub use crate::bar::Bar; Since the first re-export is doc hidden, should only this re-export be hidden (and therefore its associated documentation "b" too) or should the re-export and the re-exported item be both hidden? I'd tend to only remove the re-export and its documentation and still make |
We have to be careful with inlining mod foo {
/// a
pub struct Bar;
}
mod bar {
/// b
#[doc(hidden)]
pub use crate::foo::Bar;
}
// shadow the re-export below
// but only in the values namespace
const Bar: usize = 0;
pub use crate::bar::Bar; The rustdoc generated for your example code and the one from mine must be different, or else we'll have the same problem as #111338 and https://predr.ag/blog/breaking-semver-in-rust-by-adding-private-type-or-import/ Treating the top-level I hate jumping in to point out concerns without having a constructive suggestion on how to do better, but I genuinely don't see a good way out of this right now. |
JSON output handles things differently compared to the HTML output. And in the end, |
Yeah. Making I propose closing this PR and opening a new one to document the new decision (and fix any weird inconsistencies): |
👍 Closing then and thanks everyone for the feedback! |
I'm not familiar with the HTML output, and I just realized my earlier code example is slightly broken. Here's an attempt at clarifying what I meant with respect to the JSON output (checked in the playground this time). In the code below, we cannot replace mod upstream {
mod foo {
/// a
pub struct Bar;
}
mod bar {
/// b
#[doc(hidden)]
pub use super::foo::*;
// shadow the re-export below
// but only in the values namespace
const Bar: usize = 0;
}
// This line causes compilation to fail:
// pub use bar::Bar;
//
// But replacing it with this seemingly-equivalent line
// makes the problem go away -- so it isn't actually equivalent:
pub use foo::Bar;
}
// imagine this is a downstream crate
mod downstream {
fn make_bar() -> crate::upstream::Bar {
crate::upstream::Bar
}
} |
I should have precised but this behaviour enforcement/clarification is only for the HTML output. I'll precise it when I'll open the new PR so it's more clear. The JSON output is handling re-exports differently since its format allows it. |
Ah yes that makes sense now! |
…n-macros, r=notriddle Fix re-export of doc hidden macro not showing up It's part of the follow-up of rust-lang#109697. Re-exports of doc hidden macros should be visible. It was the only kind of re-export of doc hidden item that didn't show up. r? `@notriddle`
…ddle Add chapter in rustdoc book for re-exports and add a regression test for `#[doc(hidden)]` behaviour Fixes rust-lang#109449. Fixes rust-lang#53417. After the discussion in rust-lang#109697, I made a few PRs to fix a few corner cases: * rust-lang#112178 * rust-lang#112108 * rust-lang#111997 With this I think I covered all cases. Only thing missing at this point was a chapter covering re-exports in the rustdoc book. r? `@notriddle`
Fixes #109449.
Fixes #53417.
I also took the comments from zulip about
#[doc(no_inline)]
and glob re-exports more globally.So now, for non-glob re-exports,
#[doc(hidden)]
items are treated the same as private items: they are inlined.For glob re-exports,
#[doc(hidden)]
items are not inlined (contrary to private items).If there
#[doc(no_inline)]
on a glob re-export, the glob re-export definition will displayed and the referenced items won't be inlined.cc @petrochenkov
r? @notriddle