Skip to content
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

Funky rustdoc behavior when pub use path_to::Trait as _; for public-in-private item #92379

Open
steffahn opened this issue Dec 29, 2021 · 10 comments
Labels
A-rustdoc-ui Area: Rustdoc UI (generated HTML) C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@steffahn
Copy link
Member

steffahn commented Dec 29, 2021

Something like

mod m {
    pub trait Hello {
        fn hello() {}
    }
    pub trait World {
        fn world() {}
    }
}

pub use m::Hello as _;
pub use m::World as _;

creates documentation listing two traits called "_"

Screenshot_325

both of which link to the same URL .../target/doc/crate_name/trait._.html and which contains documentation for one of the two traits, chosen seemingly at random.

When I add a few implementations, sometimes (not very reproducably) I've even gotten a weirdly broken page. E.g. I sometimes get

mod m {
    pub trait Hello {
        fn hello() {}
    }

    pub trait World {
        fn world() {}
    }

    impl World for u8 {
        fn world() {}
    }

    impl World for u16 {
        fn world() {}
    }

    impl World for u32 {
        fn world() {}
    }
}

pub use m::Hello as _;
pub use m::World as _;

to generate a page that looks like this

Screenshot_326

@rustbot label T-rustdoc, A-rustdoc-ui

@steffahn steffahn added the C-bug Category: This is a bug. label Dec 29, 2021
@rustbot rustbot added A-rustdoc-ui Area: Rustdoc UI (generated HTML) T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Dec 29, 2021
@steffahn steffahn changed the title Funky rustdoc behavior when pub use some::Trait as _; Funky rustdoc behavior when pub use path_to::Trait as _; Dec 29, 2021
@steffahn steffahn changed the title Funky rustdoc behavior when pub use path_to::Trait as _; Funky rustdoc behavior when pub use path_to::Trait as _; for public-in-private item Dec 29, 2021
@ThePuzzlemaker
Copy link
Contributor

@rustbot claim
I've looked into this a bit and I've found a way to fix the main problem, but it causes a bit of a UI papercut itself--it will display the original names, but it doesn't say in any way that they've been reexported as _, so I need some advice on how I should handle this.
Using the second snippet provided with a small patch, it looks like this:
image
This is definitely better, but note that it does not display as pub use Hello as _ or otherwise show that it's not a full re-export. I'm not sure how exactly I should handle this, whether I should try to coerce it into displaying like regular re-exports, or add some sort of thing to show that it is not a regular re-export.

@ThePuzzlemaker
Copy link
Contributor

Granted, this kind of feels like an edge case to me, I don't (personally) find any practical advantage to having a trait that you can only use the methods of but not mention or quantify over, e.g. for a fn foo<T: Trait>(x: T)-like function.

@steffahn
Copy link
Member Author

steffahn commented Dec 29, 2021

I would feel like displaying it like a regular re-export feels like a good solution, and also displaying a warning that goes away by adding #[doc(no_inline)] could be a feasible approach. After all, the documentation situation when it's just the re-export documentation is somewhat suboptimal, too, because the traits are completely undocumented in this case, so a warning feels right; and after all it is a rather weird edge case that probably doesn't need special support, just obviously buggy behavior - like the current one - should be avoided.

^^^^ Just my personal opinion/interpretation right now 😉, and I haven't actually thought for more than a handful of minutes about how best to resolve this issue yet.


Following the approach explained above, the same thing should probably also apply for a case without public-in-private items, but with explicit #[doc(inline)] e.g.

pub trait Foo {}

#[doc(inline)]
pub use Foo as _;

should also effectively ignore the #[doc(inline)], but also issue a warning.

@steffahn
Copy link
Member Author

I don't (personally) find any practical advantage to having a trait that you can only use the methods of but not mention or quantify over

I mean, I actually came up with the idea for code like this because it might have some practical use-case. It's like the ultimate sealed trait; you cannot implement it, you can't even use it in trait bounds. A bit awkward to bring into scope (since only a use path::to::module::*; will to it, but other than that, it's almost like the perfect extension trait: You're not really supposed to implement an extension trait, or to use it in a trait bound.

Of course the problems are that it's impossible to get properly documented, and it's probably confusing as hell for most users anyways, etc, so ultimately it's a bad idea.

@GuillaumeGomez
Copy link
Member

I don't have the completely broken page:

Screenshot from 2021-12-29 13-49-56

Which rustdoc version did you use?

@steffahn
Copy link
Member Author

steffahn commented Dec 29, 2021

@GuillaumeGomez I used

rustdoc 1.59.0-nightly (e100ec5bc 2021-12-21)

on Windows. I tested with

rustdoc 1.57.0 (f1edd0429 2021-11-29)

now and it gives a different-looking broken page

Screenshot_327

As mentioned above, this result is not reproducible on every build, it seems to happen randomly. Try doing cargo clean and cargo doc a few times, and you might get it. E.g. now, trying it again it took me 8 tries in a row. It's sometimes rendering a non-broken version of Hello or World, I guess the chance of the broken page at most 33%.

@GuillaumeGomez
Copy link
Member

The rustdoc builds are reproducible normally, if not we have a much bigger issue on our hands... At this point, I wonder if the problem isn't your web browser?

@steffahn
Copy link
Member Author

They aren't reproducible in this case, but I suppose the reason is just that it's because there's two different items that get documented under the same URL? If rustdoc's reproducibility relies on the fact that no two pages go to the same location, then that would make sense to me. You should more easily be able to create non-reproducible results with the original example where I noted

both of which link to the same URL .../target/doc/crate_name/trait._.html and which contains documentation for one of the two traits, chosen seemingly at random.

If you build that example yourself, multiple times (with cargo clean!), are you not getting random non-reproducible results (regarding whether the documented trait has a hello method or a world method)?!?

@GuillaumeGomez
Copy link
Member

Oh hold on, that might be a windows-specific issue: I wonder if the file is being written from two places at the same time (we have a thread handling file writing on Windows).

@lolbinarycat
Copy link
Contributor

triage: this is what it looks like now

This is a pretty pathological edge case, I don't know if we can handle this much better than we do.

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-ui Area: Rustdoc UI (generated HTML) C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants