Skip to content

rustdoc does not detect broken markdown due to missing links (except for links without a space) #141227

Open
@RalfJung

Description

@RalfJung
Member

I changed [allocated object] to [allocation] in docs, and strangely that triggered an error. Turns out the docs had a broken link, which you can see live at https://doc.rust-lang.org/1.87.0/std/primitive.pointer.html#method.split_at_mut_unchecked (note the "[allocated object]") -- but rustdoc somehow wouldn't complain unless the link text has no spaces? Something very strange is going on here.

See #141224 for context. The error emitted after the change is below:

  error: unresolved link to `allocation`
      --> library/core/src/ptr/mut_ptr.rs:1851:54
       |
  1851 |     /// `mid` must be [in-bounds] of the underlying [allocation].
       |                                                      ^^^^^^^^^^ no item named `allocation` in scope
       |
       = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
       = note: `-D rustdoc::broken-intra-doc-links` implied by `-D warnings`
       = help: to override `-D warnings` add `#[allow(rustdoc::broken_intra_doc_links)]`

Possibly related: #130126

Activity

added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on May 18, 2025
added
T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.
on May 18, 2025
added
A-intra-doc-linksArea: Intra-doc links, the ability to link to items in docs by name
and removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on May 18, 2025
fmease

fmease commented on May 18, 2025

@fmease
Member

Simply put, [a b c] is not an intra-doc link "candidate" while [a] is. The former is just a broken CommonMark shortcut reference link. Arguably, we should do something here though (i.e., emitting some lint).

added
C-enhancementCategory: An issue proposing an enhancement or a PR with one.
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
and removed
C-bugCategory: This is a bug.
on May 18, 2025
lolbinarycat

lolbinarycat commented on May 23, 2025

@lolbinarycat
Contributor

i actually have a full fix for this up at #132748, but it had to be toned back with some additional heirustics to avoid causing massive code churn, both in std and in the wider ecosystem.

we could split out a more strict allow-by-default lint, but currently the formatting info is stripped away by the time we decide to emit the lint, so it would be non-trivial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-intra-doc-linksArea: Intra-doc links, the ability to link to items in docs by nameA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-enhancementCategory: An issue proposing an enhancement or a PR with one.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

        Participants

        @RalfJung@fmease@lolbinarycat@rustbot

        Issue actions

          rustdoc does not detect broken markdown due to missing links (except for links without a space) · Issue #141227 · rust-lang/rust