Skip to content

Rustdoc: pub useing and/or globbing a submodule containing a pub macro (Macros 2.0) does not document the macro #87257

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

Closed
bstrie opened this issue Jul 18, 2021 · 4 comments · Fixed by #88019
Assignees
Labels
A-decl-macros-2-0 Area: Declarative macros 2.0 (#39412) C-bug Category: This is a bug. requires-nightly This issue requires a nightly compiler in some way. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@bstrie
Copy link
Contributor

bstrie commented Jul 18, 2021

Rustdoc will properly generate the documentation for a Macros-2.0 macro when that macro is defined in a directly-exported submodule, e.g. pub mod foo { pub macro bar(). But if the module is not directly exported (pub mod foo {) but indirectly exported (pub use foo;) then the macro no longer exists in the documentation: the module documentation for mod foo will not mention it, and no page for the macro will be generated at all. The same problem occurs if a macro is exported via pub use foo::*.

Note that these are not problems with name resolution itself: Rust code will resolve the exported macro properly, the docs merely don't show it.

Example:

#![feature(decl_macro)]

mod outer {
    /// I am module documentation
    pub mod inner {
        /// I am macro documentation
        pub macro some_macro() {}

        /// I am struct documentation
        pub struct SomeStruct;
    }
}

// GOOD: this shows up properly in the top-level crate docs
pub use outer::inner::SomeStruct;

// GOOD: this shows up properly in the top-level crate docs
pub use outer::inner::some_macro;

// BAD: the `inner` module-level documentation shows the struct, but not the macro.
// If `outer` did not exist and `inner` were instead directly exported,
// then both items show up as expected.
pub use outer::inner;

(In the above example even though some_macro is not listed in the docs for inner, the docs page for some_macro will still be generated because of the explicit pub use outer::inner::some_macro; if this line is removed then that page will also vanish.)

Presumably this is a descendant of #74355 , where Macros-2.0 were not being documented at the correct paths. The fix for that issue landed in #77862 , although the fix itself appears to be regarded as a deplorable hack, and presumably the fix for this issue should not attempt to further hack the hack and instead make Macros 2.0 Just Work with Rustdoc.

@bstrie bstrie added A-decl-macros-2-0 Area: Declarative macros 2.0 (#39412) T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Jul 18, 2021
@bstrie
Copy link
Contributor Author

bstrie commented Jul 18, 2021

From Zulip:

Basically what's going on is that rustdoc is trying to reconstruct the privacy information after the fact. Rustc_resolve should just do that itself instead of giving rustdoc wrong information.

@jyn514
Copy link
Member

jyn514 commented Jul 18, 2021

Here is the proper fix I mentioned: #79396 (comment)

@jyn514
Copy link
Member

jyn514 commented Jul 18, 2021

See also #73754, which has the same root cause.

@jyn514 jyn514 added the requires-nightly This issue requires a nightly compiler in some way. label Jul 20, 2021
@camelid camelid added the C-bug Category: This is a bug. label Jul 21, 2021
@inquisitivecrystal inquisitivecrystal self-assigned this Aug 6, 2021
@inquisitivecrystal
Copy link
Contributor

This should get fixed as part of #87406.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-decl-macros-2-0 Area: Declarative macros 2.0 (#39412) C-bug Category: This is a bug. requires-nightly This issue requires a nightly compiler in some way. 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.

4 participants