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 incorrectly raises a rustdoc::redundant_explicit_links warning when the link is in fact required #123158

Closed
koshell opened this issue Mar 28, 2024 · 1 comment · Fixed by #123162
Assignees
Labels
C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@koshell
Copy link

koshell commented Mar 28, 2024

I discovered this oddity while writing docs for a crate. Apologies if this isn't the correct place to report a bug, there didn't appear to be a rustdoc specific tracker anywhere I could find.

I created a new crate cargo new and messed around till I could reproduce the issue. This is the minimum reproducible example:

//! [**`SomeTrait`**](SomeTrait):

pub trait SomeTrait {}

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

This returns this warning:

warning: redundant explicit link target
 --> src\main.rs:1:23
  |
1 | //! [**`SomeTrait`**](SomeTrait):
  |        -----------    ^^^^^^^^^ explicit target is redundant
  |        |
  |        because label contains path that resolves to same destination
  |
  = note: when a link's destination is not specified,
          the label is used to resolve intra-doc links
  = note: `#[warn(rustdoc::redundant_explicit_links)]` on by default
help: remove explicit link target
  |
1 | //! [`SomeTrait`]:
  |     ~~~~~~~~~~~~~

However if you remove the explicit link you get this:

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

I originally thought the : might be the issue. Maybe it was confusing it with a link fragment as described in the docs but you get the same error without it:

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

Meta

Confirmed to exist on stable and nightly.

Stable

rustc --version --verbose:

rustc 1.76.0 (07dca489a 2024-02-04)
binary: rustc
commit-hash: 07dca489ac2d933c78d3c5158e3f43beefeb02ce
commit-date: 2024-02-04
host: x86_64-pc-windows-msvc
release: 1.76.0
LLVM version: 17.0.6

Nightly

rustc --version --verbose:

rustc 1.78.0-nightly (766bdce74 2024-03-16)
binary: rustc
commit-hash: 766bdce744d531267d53ba2a3f9ffcda69fb9b17
commit-date: 2024-03-16
host: x86_64-pc-windows-msvc
release: 1.78.0-nightly
LLVM version: 18.1.2

@koshell koshell added the C-bug Category: This is a bug. label Mar 28, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 28, 2024
@GuillaumeGomez GuillaumeGomez added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 28, 2024
@GuillaumeGomez GuillaumeGomez self-assigned this Mar 28, 2024
@GuillaumeGomez
Copy link
Member

Thanks for the detailed explanations! Taking a look.

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Mar 28, 2024
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Mar 28, 2024
@bors bors closed this as completed in cba164c Mar 28, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 28, 2024
Rollup merge of rust-lang#123162 - GuillaumeGomez:fix-123158, r=notriddle

Correctly get complete intra-doc link data

Fixes rust-lang#123158.

The problem was that we didn't take into account cases where there would be content other than backticks into the intra doc link definition.

r? `@notriddle`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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

Successfully merging a pull request may close this issue.

3 participants