Skip to content

rustdoc: Fix cosmetic issues when reporting unresolved paths in broken_intra_doc_links#156022

Open
tonywu6 wants to merge 3 commits intorust-lang:mainfrom
tonywu6:main
Open

rustdoc: Fix cosmetic issues when reporting unresolved paths in broken_intra_doc_links#156022
tonywu6 wants to merge 3 commits intorust-lang:mainfrom
tonywu6:main

Conversation

@tonywu6
Copy link
Copy Markdown
Contributor

@tonywu6 tonywu6 commented May 1, 2026

Fix some minor issues with how the rustdoc::broken_intra_doc_links lint labels unresolved items:

  • a469a4a For unresolved "extern prelude" links like ::unresolved::item
    • Previously: no item named `` in scope
    • Now: no item named `unresolved` in scope
  • eeb96fa Some malformed paths are now accounted for, for example:
    • std:::path
      • Previously: no item named `std:` in scope
      • Now: has invalid path separator
    • std::::path
      • Previously: no item named `` in scope
      • Now: has invalid path separator

This PR is broken down into a few commits with their own descriptions, which I hope makes reviewing easier!

tonywu6 added 3 commits May 1, 2026 07:56
- Add a check while trying to resolve parents, so that for links like
  [`::unresolved::path`], rustdoc will say:
    "no item named `unresolved` in scope"
  instead of:
    "no item named `` in scope"

- Update corresponding test
- Check whether an unresolved path is in fact invalid. This prevents rustdoc
  from emitting nonsensical diagnostics like:

  - "no item named `std:` in scope"
  - "no item named `` in scope"

  Instead rustdoc will now say "has invalid path separator" (the same message
  from `MalformedGenerics::InvalidPathSeparator`)

  This is done by checking whether each path segment is empty or contains extra ":"
  after it's been split by the path separator "::".

- Add a dedicated test `tests/rustdoc-ui/intra-doc/invalid-path-separator.rs`
  which contains some examples of such invalid paths.

Some refactoring because of this extra check:

- Lift the "Check if parent of path gets resolved" logic into a closure,
  which I think makes the control flow more digestible.
- Lift some extra diagnostic notes into a reused closure.

- Some unrelated test snapshots have been updated because of this new check.
`resolution_failure` has a loop to handle possibly multiple `ResolutionFailure`s
but some branches in it was returning early instead of continuing the loop.
Changing them to `continue` affects no test.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels May 1, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 1, 2026

r? @lolbinarycat

rustbot has assigned @lolbinarycat.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: rustdoc
  • rustdoc expanded to 9 candidates
  • Random selection from GuillaumeGomez, fmease, lolbinarycat, notriddle

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

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants