Skip to content

Unhelpful rustdoc [src] link for struct generated by macro #47817

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

Closed
dtolnay opened this issue Jan 28, 2018 · 1 comment
Closed

Unhelpful rustdoc [src] link for struct generated by macro #47817

dtolnay opened this issue Jan 28, 2018 · 1 comment
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one. T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@dtolnay
Copy link
Member

dtolnay commented Jan 28, 2018

In dtolnay/syn#304 we have a macro_rules macro that adds some derive attributes to most of our syntax tree structs. Conceptually it looks like this:

macro_rules! ast_struct {
    (pub struct $name:ident $body:tt) => {
        #[derive(Clone)]
        pub struct $name $body
    }
}

ast_struct! {
    pub struct S {
        /* ... */
    }
}

In our case the macro definition and invocation are always in different files but the code above is sufficient to reproduce the issue. If you document this code with cargo doc, the [src] link at the top of struct.S.html points to the line pub struct $name $body, as far as I can tell because this is where the first non-attribute token (pub) of the final struct definition came from.

I propose that it would be more often correct to have [src] point to wherever the *name* token of the item came from, in this case the $name token which originates from the line pub struct S.

@dtolnay dtolnay added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Jan 28, 2018
@GuillaumeGomez GuillaumeGomez added T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. T-dev-tools-rustdoc labels Jan 29, 2018
@TimNN TimNN added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jan 30, 2018
@jyn514
Copy link
Member

jyn514 commented Sep 7, 2020

Closing as duplicate of #39726

@jyn514 jyn514 closed this as completed Sep 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one. T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. 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