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

rustdoc: broken_intra_doc_links is incorrectly reported when linking to a proc macro #91274

Open
camelid opened this issue Nov 26, 2021 · 2 comments
Assignees
Labels
A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-proc-macros Area: Procedural 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

@camelid
Copy link
Member

camelid commented Nov 26, 2021

Rustdoc only emits a documentation page for my_macro as a macro; there's no function page for it.

Note that the link indeed fails to resolve.

Code

//! Link to [`my_macro`].

#![crate_type = "proc-macro"]

extern crate proc_macro;

#[proc_macro]
pub fn my_macro(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
    input
}

Output

warning: `my_macro` is both a function and a macro
 --> foo.rs:1:15
  |
1 | //! Link to [`my_macro`].
  |               ^^^^^^^^ ambiguous link
  |
  = note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default
help: to link to the function, add parentheses
  |
1 | //! Link to [`my_macro()`].
  |                       ++
help: to link to the macro, add an exclamation mark
  |
1 | //! Link to [`my_macro!`].
  |                       +

warning: 1 warning emitted
@camelid camelid added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name A-proc-macros Area: Procedural macros labels Nov 26, 2021
@camelid
Copy link
Member Author

camelid commented Nov 26, 2021

Adding the ! as suggested causes the link to resolve successfully.

However, I found another, related bug: When I add (), the link resolves successfully—to the macro!

@jyn514
Copy link
Member

jyn514 commented Nov 27, 2021

Hmm, I don't think my_macro() resolving is actually a bug? It is a function, it just happens to also be a macro.

I agree that the warning isn't helpful though since the link is the same in both cases.

bors added a commit to rust-lang-ci/rust that referenced this issue Dec 1, 2021
Deny warnings in rustdoc non-UI tests

These warnings were silently ignored since they did not appear in a
`.stderr` file and did not fail the test. With this change, warnings in
tests are denied, causing the tests to fail if they have warnings.

This change has already led me to find a bug in rustdoc (rust-lang#91274) and a
useless test (`src/test/rustdoc/primitive/primitive-generic-impl.rs`,
though its uselessness is unrelated to its warnings).

r? `@jyn514`
@lolbinarycat lolbinarycat self-assigned this Nov 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-proc-macros Area: Procedural 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