Skip to content

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

Open
tonywu6 wants to merge 4 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 4 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!

Fixes #141095

- 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
@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

Copy link
Copy Markdown
Contributor

@lolbinarycat lolbinarycat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First commit is pretty good, latter commits seem to make a lot of changes that are not strictly needed.

View changes since this review

Comment thread src/librustdoc/passes/collect_intra_doc_links.rs Outdated
Comment thread src/librustdoc/passes/collect_intra_doc_links.rs Outdated
Comment thread src/librustdoc/passes/collect_intra_doc_links.rs Outdated
Comment thread src/librustdoc/passes/collect_intra_doc_links.rs Outdated
Comment thread src/librustdoc/passes/collect_intra_doc_links.rs Outdated
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 8, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 8, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

- 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`
  for this.

- Some unrelated test snapshots have been updated because of this new check.
Copy link
Copy Markdown
Contributor

@lolbinarycat lolbinarycat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! Just one last thing.

(also, i'd like if the last commit's message mentioned variant_count somewhere, but it's not required)

View changes since this review

Comment thread src/librustdoc/passes/collect_intra_doc_links.rs Outdated
Replace a hardcoded constant with `mem::variant_count` to keep in-sync
with the `ResolutionFailure` enum.
Comment thread src/librustdoc/passes/collect_intra_doc_links.rs Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

rustdoc: terse diagnostic on malformed intra-doc link (single instead of double colon)

3 participants