-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Rustdoc doesn't play well with use ... as _
syntax
#97615
Comments
The problem is that we "inline" them. The solution could be to keep the original name (and it would be a link to the original location), but if the item is originally in a private module, then there is no link generated and we would end up with I'm not really sure what would be the best course of action in here... cc @rust-lang/rustdoc |
Is there any usecase for an anonymous reexport of a privately scoped trait? Seems like an edge case we don't need to really support. |
I think it's a good point. For the more general problem of the reexports, we can always come back to it later on. I'll send a PR to explicitly ignore anonymous reexports. |
Let's not rush with not-supporting this. We use this pattern in our code extensively. We use it to export extension traits. For example, we have a trait that provides extension traits to the standard library mod option {
pub trait OptionExt<T> { /* our methods to put on all Option types */ }
impl<T> OptionExt<T> for Option<T> { /* */ }
}
pub mod prelude {
pub use crate::option::OptionExt as _;
} We do it this way to guarantee that the users of our extension traits crate will not be able to both:
|
For making the trait sealed the standard pattern is to use The latter requirement seems like an anti-pattern to me. I blanket-ban all glob imports in my projects so that would make your library unusable in them. |
That's true, but it is not the main benefit of this pattern. The trait is sealed for free when we do this.
Clippy specifically allows configuring
So things like Requiring that the extension trait is available only via |
And wildcard_imports is allow-by-default anyway. I have just chosen to enable it, and I don't allow prelude imports, because I believe that results in easier to navigate code and all crates should be usable still.
These are only re-exports of items that have other public paths. I know there are other buggy crates that force using paths like |
Anyway, one approach to a fix I can think of is for rustdoc to pretend that |
@Nemo157 you make very good points, but
Ideal fixIdeally, a reexported symbol should have the additional context that indicates that it is unreachable. That sounds like a big-effort feature for Low-effort FixIf we want to have a low-effort fix for this problem, we could just generate a name for the reexported symbol there prefixed with some easy-to-understand token that makes it obvious the symbol is unreachable. Generating The Symbol Name Based On Trait NameWe could generate the name for the reexport like this for example Generating The Symbol Name Based On Reexport IdentityThe reexport can be identified by its position in the module tree. For example, we could take the file/line/column to generate the symbol name like this |
triage: seems to be an exact duplicate of #92379 |
I tried this code:
I expected to see this happen: there should be a way to view all the items reexported anonymously in docs. Maybe even just expose them by original names in docs.
Instead, this happened:
The traits are visible in rustodoc as a single
prelude::_
And when you click on any of
_
links you see only this:Looks like
rustdoc
writes the docs for the arbitrary item reexported withuse ... as _;
Meta
rustdoc --version --verbose
:rustc --version --verbose
The text was updated successfully, but these errors were encountered: