Skip to content

rustdoc emits confusing error for link to enum struct field #85756

@joshlf

Description

@joshlf

Given the following code with a broken intra-doc link (note the bas instead of baz):

pub enum Foo {
    Bar {
        /// A baz.
        baz: u8,
        /// Just like [`baz`].
        ///
        /// [`baz`]: crate::Foo::Bar::bas
        blah: u8,
    }
}

I would expect cargo doc to emit an error along the lines of:

warning: unresolved link to `self::Foo::Bar::bas`
 --> src/lib.rs:7:22
  |
7 |         /// [`baz`]: crate::Foo::Bar::bas
  |                      ^^^^^^^^^^^^^^^^^^^^ the enum variant `Foo::Bar` has no field named `bas`
  |
  = note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default

Instead, cargo doc emits this error:

warning: unresolved link to `self::Foo::Bar::bas`
 --> src/lib.rs:7:22
  |
7 |         /// [`baz`]: crate::Foo::Bar::bas
  |                      ^^^^^^^^^^^^^^^^^^^^ the enum `Foo` has no variant or associated item named `bas`
  |
  = note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default

When I first encountered this in real code, I thought that the confusing error message was a symptom of the fact that doc comments on enum variant struct fields were not supported, so I almost gave up before realizing that it was just a confusingly-worded error message.

Meta

$ rustdoc --version
rustdoc 1.54.0-nightly (ca82264ec 2021-05-09)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-intra-doc-linksArea: Intra-doc links, the ability to link to items in docs by nameC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions