Skip to content

rustdoc: macros expanded from macros don't get their rules documented correctly #89367

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
remexre opened this issue Sep 29, 2021 · 5 comments
Closed
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@remexre
Copy link
Contributor

remexre commented Sep 29, 2021

When writing a macro_rules! macro that expands to another macro_rules! macro, the Rustdoc shows the source-code tokens pre-outer-macro-expansion in the rules for the inner macro. I was expecting to see something like the expansion in trace_macros!(), which does have the post-expansion rules.

Meta

rustdoc --version --verbose:

rustdoc 1.53.0
binary: rustdoc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-linux-gnu
release: 1.53.0
LLVM version: 12.0.1
@remexre remexre added the C-bug Category: This is a bug. label Sep 29, 2021
@jyn514
Copy link
Member

jyn514 commented Sep 29, 2021

@remexre can you give an example of this? I don't know what the difference would be between pre- and post-expansion.

@jyn514 jyn514 added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Sep 29, 2021
@remexre
Copy link
Contributor Author

remexre commented Sep 29, 2021

The example I have on hand is the result of expanding https://git.sr.ht/~remexre/ia/tree/691c22fb86e162f9b0360b03d987275134b66c64/item/engine/util.rs#L48 gets documented like:

image

I can make a minimized example tonight if that'd be more helpful.

@jyn514
Copy link
Member

jyn514 commented Sep 29, 2021

I can make a minimized example tonight if that'd be more helpful.

That would be great, thanks!

@remexre
Copy link
Contributor Author

remexre commented Sep 30, 2021

Okay, the following program:

macro_rules! foo {
    ($name:ident => $($body:tt)*) => { foo!([$], $name, $($body)*); };
    ([$dollar:tt], $name:ident, $($body:tt)*) => {
        #[macro_export]
        macro_rules! bar {
            ($dollar $name :tt) => { $($body)* };
        }
    };
}

foo!(msg => println!($msg));

fn main() {
    bar!("Hello, world!");
}

gets the bar macro documented as:

macro_rules! bar {
    ($dollar $name :tt) => { ... };
}

rather than as

macro_rules! bar {
    ($ msg :tt) => { ... };
}

@camelid
Copy link
Member

camelid commented Dec 27, 2021

This is fixed now, probably by #86282 (cc #45939).

image

@camelid camelid closed this as completed Dec 27, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) 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

3 participants