Skip to content

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

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

Open
RalfJung opened this issue May 18, 2025 · 2 comments
Labels
A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-enhancement Category: An issue proposing an enhancement or a PR with one. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@RalfJung
Copy link
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

@RalfJung RalfJung added the C-bug Category: This is a bug. label May 18, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 18, 2025
@RalfJung RalfJung added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label May 18, 2025
@fmease fmease added A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels May 18, 2025
@fmease
Copy link
Member

fmease commented May 18, 2025

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).

@fmease fmease added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. and removed C-bug Category: This is a bug. labels May 18, 2025
@lolbinarycat
Copy link
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
Labels
A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-enhancement Category: An issue proposing an enhancement or a PR with one. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants