Skip to content

rustdoc incorrectly raises a rustdoc::redundant_explicit_links warning when the link is in fact required #123158

Closed
@koshell

Description

@koshell

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

Metadata

Metadata

Labels

C-bugCategory: This is a bug.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions