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

Documentation of a re-export doesn't appear on level-two re-export #81893

Open
jplatte opened this issue Feb 8, 2021 · 22 comments · Fixed by #104292
Open

Documentation of a re-export doesn't appear on level-two re-export #81893

jplatte opened this issue Feb 8, 2021 · 22 comments · Fixed by #104292
Labels
C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@jplatte
Copy link
Contributor

jplatte commented Feb 8, 2021

I have a macro crate with a "peer dependency" on another crate, i.e. I can't write doctests for the macro itself without introducing circular dev-dependencies which are kind of annoying. The other crate re-exports the macro and the macro is actually expected to only ever be used through there, so I documented the re-export instead. However, there's another higher-level crate that re-exports a bunch of other crates entirely including the one that re-exports the macro. In the documentation of the higher-level crate, the documentation for the macro does not appear, while it appears on the "level-one" re-export.

Minimal reproduction:

Crate foo re-exports a type from bar, which is itself a re-export of a type from baz. The docs on each of the declarations (original type definition in baz, re-exports in bar and foo) are simply the crate name

// # baz/src/lib.rs
/// baz
pub struct Type;

// # bar/src/lib.rs
/// bar
pub use baz::Type;

// # foo/src/lib.rs
/// foo
pub use bar::Type;

Here is a repo with this: https://github.com/jplatte/rust-issue-81893

I expected to see this happen: the docs of foo::Type should be foo bar baz

Instead, this happened: the docs of foo::Type are foo baz

Meta

Happens with latest nightly from rustup that has rustfmt:

rustc --version --verbose:

rustc 1.51.0-nightly (04caa632d 2021-01-30)
binary: rustc
commit-hash: 04caa632dd10c2bf64b69524c7f9c4c30a436877
commit-date: 2021-01-30
host: x86_64-unknown-linux-gnu
release: 1.51.0-nightly
LLVM version: 11.0.1
@jplatte jplatte added the C-bug Category: This is a bug. label Feb 8, 2021
@jonas-schievink jonas-schievink added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Feb 8, 2021
@jyn514
Copy link
Member

jyn514 commented Feb 9, 2021

Some related bugs:

mod a {
    /// baz
    pub struct Type;
}

mod b {
    /// bar
    pub use crate::a::Type;
}

/// foo
pub use b::Type;

only shows baz in the docs, as does

mod a {
    /// baz
    pub struct Type;
}

/// bar
pub use a::Type;

@jyn514
Copy link
Member

jyn514 commented Feb 9, 2021

A bit of trivia, not particularly helpful: In 1.33, the cross-crate issue behaved as the single crate issue and only showed baz.

@TaKO8Ki
Copy link
Member

TaKO8Ki commented Feb 15, 2021

@rustbot claim

@TaKO8Ki
Copy link
Member

TaKO8Ki commented Mar 9, 2021

It is about work on this issue!

@jyn514
Copy link
Member

jyn514 commented Apr 2, 2021

@TaKO8Ki hi, have you made any progress on this issue? No problem if not, but please comment @rustbot release-assignment if so, so other people can work on it.

@TaKO8Ki
Copy link
Member

TaKO8Ki commented Apr 2, 2021

@jyn514
I'm sorry. I was busy a while ago, but I have some time on my hands these days, so can I work on this issue some more?

@jyn514
Copy link
Member

jyn514 commented Apr 2, 2021

Sure thing. If it helps, I think this is the place to look:

fn merge_attrs(

@TaKO8Ki
Copy link
Member

TaKO8Ki commented Apr 2, 2021

@jyn514
Thank you! I'm going to take a look.

@GuillaumeGomez
Copy link
Member

The problem evolved a bit. With this code:

mod a {
    /// baz
    pub struct Type;
}

mod b {
    /// bar
    pub use crate::a::Type;
}

/// foo
pub use b::Type;

We now have foo baz documentation for Type.

@jplatte
Copy link
Contributor Author

jplatte commented Nov 7, 2022

Isn't that the same thing I wrote originally? Or is the change that it happens inside one crate as well now (I don't think I tested that scenario before)?

@GuillaumeGomez
Copy link
Member

Sorry, you are absolutely right. I worked on something similar recently and checked if the problem still existed and forgot to check your first message. Sorry. I'm working on this issue to fix it definitely.

@jplatte
Copy link
Contributor Author

jplatte commented Nov 15, 2022

@GuillaumeGomez
Copy link
Member

Can you write a minimum code to reproduce the issue please? I think the proc-macro call might be messing with it.

Aaron1011 pushed a commit to Aaron1011/rust that referenced this issue Jan 6, 2023
…-doc-comments, r=notriddle

Fix missing reexports' doc comments

Fixes rust-lang#81893.

The issue was that an import directly "links" to the target without the intermediate imports. Unfortunately, to fix this bug we need to go through them one by one. To do so, I take the import path direct parent (so `b` in `a::b::c`) and then look for `c` into it.

r? `@notriddle`
@jplatte
Copy link
Contributor Author

jplatte commented Jan 30, 2023

Updated https://github.com/jplatte/rust-issue-81893 with a new reproducer.

@GuillaumeGomez
Copy link
Member

Found out about this issue: the problem is that reexports don't exist in the Rust ABI at the moment. There is work in progress to add support for it but we're far from done. Until then, I'm afraid that foreign reexports docs won't appear...

@jyn514
Copy link
Member

jyn514 commented Mar 15, 2023

what are you talking about? "rust abi" isn't a thing and it wouldn't involve rustdoc if it did, abi is a codegen thing and rustdoc doesn't do codegen.

@GuillaumeGomez
Copy link
Member

By that I meant that this information isn't stored in the rmeta file. That's what I called (wrongly apparently) the ABI.

@jyn514
Copy link
Member

jyn514 commented Mar 15, 2023

ok. .rmeta files contain metadata; here's the section of the dev-guide that talks about them: https://rustc-dev-guide.rust-lang.org/backend/libs-and-metadata.html

it's ok not to know everything about the compiler, but please don't make up random words if you're not sure the right word, i would much rather you say "this information isn't stored in the rmeta file" than confuse everyone involved.

@GuillaumeGomez
Copy link
Member

Thanks!

@jyn514
Copy link
Member

jyn514 commented Mar 15, 2023

also there are two parts to this issue, one is within the same crate and one is across crates; only the one across crates can be affected by what's in the metadata file. is the part within the same crate fixed? if not, i think it's unlikely that metadata is related.

@GuillaumeGomez
Copy link
Member

In the same crate it was fixed recently. I wrote a blog post recently about the work on how re-exports are handled in rustdoc here. I also describe how "intermediate" re-exports are handled. So now, the only bug remaining is about foreign re-exports.

@workingjubilee
Copy link
Member

"rust abi" isnt a thing

Strictly speaking, there is such a thing as "the Rust ABI".

It is unstable, but implicitly, it is defined by "whatever we are currently doing during codegen". However, "ABI" only concerns parts of the program that are reachable at runtime, such as a struct's binary layout, what registers data is passed in, or thread-local storage data. It would be... a strange day where that sort of thing is relevant to rustdoc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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

Successfully merging a pull request may close this issue.

7 participants