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 omits source line numbers in diagnostics if they originate in a macro #84694

Open
jyn514 opened this issue Apr 29, 2021 · 1 comment
Open
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jyn514
Copy link
Member

jyn514 commented Apr 29, 2021

I tried this code:

top_level_options!(
/// The top-level command-line options struct.
///
/// For each option, one has to specify how it behaves with regard to the
/// dependency tracking system of incremental compilation. This is done via the
/// square-bracketed directive after the field type. The options are:
///
/// [TRACKED]

I expected to see this happen: Rustdoc shows the line number of the broken link, like it does normally:

warning: unresolved link to `x`
 --> src/lib.rs:1:6
  |
1 | //! [x]
  |      ^ no item named `x` in scope
  |
  = note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default
  = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`

Instead, this happened:

 Documenting rustc_session v0.0.0 (/checkout/compiler/rustc_session)
error: unresolved link to `TRACKED`
   --> compiler/rustc_session/src/options.rs:61:12
    |
61  |           $( #[$top_level_attr] )*
...
...
97  | / top_level_options!(
99  | |     ///
99  | |     ///
100 | |     /// For each option, one has to specify how it behaves with regard to the
201 | |     }
202 | | );
    | |__- in this macro invocation
    |
    |
    = note: `-D rustdoc::broken-intra-doc-links` implied by `-D warnings`
    = note: the link appears in this line:
            
            [TRACKED]
             ^^^^^^^
    = note: no item named `TRACKED` in scope
    = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`

Meta

rustc --version --verbose:

Originally posted by @rust-log-analyzer in #84233 (comment)

@jyn514 jyn514 added A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) 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 labels Apr 29, 2021
@jyn514
Copy link
Member Author

jyn514 commented Apr 29, 2021

I think the fix is to extend source_span_for_markdown_range to work with macros:

let span = super::source_span_for_markdown_range(tcx, dox, link_range, &item.attrs);

@Noratrieb Noratrieb added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants