Skip to content

manual_intra_doc_links: lint hardcoded .html links in docs - #17716

Open
notriddle wants to merge 5 commits into
rust-lang:masterfrom
notriddle:notriddle/hand-written-intra-doc-links
Open

notriddle wants to merge 5 commits into
rust-lang:masterfrom
notriddle:notriddle/hand-written-intra-doc-links

Conversation

@notriddle

@notriddle notriddle commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Encourages documentation authors to write links using paths, instead of writing rustdoc URLs by hand.

This lint detects the two common cases: local URLs and docs.rs. It avoids warning on paths that point at crates that aren't dependencies, because those can't be written as paths. It doesn't detect broken links, because rustdoc itself should detect them.

I tested all the generated intra-doc links using rustdoc in https://gist.github.com/notriddle/1db64b4aa206fce9284871ec1b4116ee

changelog: [manual_intra_doc_links]: lint hardcoded .html links in docs

Fixes #1912
Fixes rust-lang/rust#75805

@rustbot rustbot added the S-waiting-on-community-reviews Status: This is awaiting for positive reviews from the community before a maintainer is assigned. label Sep 10, 2026
@rustbot

rustbot commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request. A reviewer will take a look after it receives 2 community reviews.

In the meantime, we would highly appreciate if you could try to review any of PRs waiting on community reviews.

@rustbot rustbot added needs-fcp PRs that add, remove, or rename lints and need an FCP S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Sep 10, 2026
@github-actions

github-actions Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

Lintcheck changes for bdf5913

Lint Added Removed Changed
clippy::manual_intra_doc_links 813 0 0

This comment will be updated if you push new changes

@notriddle
notriddle force-pushed the notriddle/hand-written-intra-doc-links branch from 1803dbf to b65800d Compare September 10, 2026 07:04

@DanielEScherzer DanielEScherzer left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

community review: looking at the lintcheck reports a bunch of hits that seem like false positives, e.g. the very first one is from

This is a convenience function around the [`Adler32`] type

with the suggestion to instead link with

This is a convenience function around the [`Adler32`](struct@crate::Adler32) type.

but there wasn't any hard-coded html in the original?

It looks like the cause is the link being defined later with

/// [`Adler32`]: struct.Adler32.html

so that is where the suggestion should be emitted

View changes since this review

@notriddle
notriddle force-pushed the notriddle/hand-written-intra-doc-links branch 4 times, most recently from 136e377 to 21554f2 Compare September 10, 2026 16:15
@rustbot

This comment has been minimized.

Comment thread tests/ui/manual_intra_doc_links.stderr
Encourages documentation authors to write links using paths, instead of
writing rustdoc URLs by hand.

This lint detects the two common cases. It avoids warning on paths that
point at crates that aren't dependencies, because those can't be written
as paths. It doesn't detect broken links, because rustdoc itself should
detect them.
@notriddle
notriddle force-pushed the notriddle/hand-written-intra-doc-links branch from 21554f2 to 7f321e1 Compare September 13, 2026 03:30
@rustbot

rustbot commented Sep 13, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Comment thread tests/ui/manual_intra_doc_links.stderr
@notriddle
notriddle force-pushed the notriddle/hand-written-intra-doc-links branch from ced25f0 to ed57545 Compare September 13, 2026 21:24
@notriddle

Copy link
Copy Markdown
Contributor Author

@DanielEScherzer @poliorcetics I implemented both of your suggestions. Could you please mark your reviews as "approved"?

@poliorcetics

Copy link
Copy Markdown
Contributor

Already did :)

@DanielEScherzer DanielEScherzer left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

community review: the lintcheck report seems reasonable, and while I'm not going to pretend I understand everything here, it makes sense to me - I've left a few suggestions, but nothing that should block review by the clippy team, so approving

View changes since this review

Comment thread clippy_lints/src/doc/manual_intra_doc_links.rs Outdated
Comment thread clippy_lints/src/doc/manual_intra_doc_links.rs Outdated
help: consider linking by path instead
|
LL - //! [refdef]: index.html
LL + //! [refdef]: mod@crate

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

it seems odd that the ^^^ aren't under where the actual link is defined in cases like this where the definition is separate

help: consider linking by path instead
|
LL - /// Link to [libstd vec](https://doc.rust-lang.org/nightly/std/index.html)
LL + /// Link to [libstd vec](mod@crate::std)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what about links that are intentionally pointed at nightly (or beta) because the target doesn't reach stable for another 12 weeks?

especially since we are claiming that this lint is machine applicable... - changing nightly and beta links seems like something that is potentially incorrect

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think we should produce a lint on nightly links, because, for example, if you're on https://docs.rs/regex/latest/regex/struct.Regex.html#method.as_str and you click the str link in that function signature, you wind up on the nightly docs. This means naive users could easily go there, and copy-paste one of those URLs into their doc comment, without deliberately seeking out nightly docs.

Maybe we shouldn't make these suggestions MachineApplicable?

@@ -0,0 +1,388 @@
error: manual intra-doc link

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can you please also include test cases for

  • linking to a specific version of a crate on docs.rs, rather than latest (both where that version is the dependency version, and that version is different from the dependency version)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

linking to a specific version of a crate on docs.rs

I've added a test case for this.

both where that version is the dependency version, and that version is different from the dependency version

The lint doesn't make that distinction, because it doesn't know what the version number is. AFAICT, Clippy can't get that information at all. In any case, the test case doesn't supply it.

@rustbot rustbot removed the S-waiting-on-community-reviews Status: This is awaiting for positive reviews from the community before a maintainer is assigned. label Sep 26, 2026
@rustbot

rustbot commented Sep 26, 2026

Copy link
Copy Markdown
Collaborator

r? @llogiq

rustbot has assigned @llogiq for the project review.
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: 9 candidates
  • 9 candidates expanded to 9 candidates
  • Random selection from 6 candidates

notriddle and others added 3 commits September 26, 2026 12:29
Co-authored-by: Daniel Scherzer <daniel.e.scherzer@gmail.com>
`tests/compile-test.rs` and `clippy_dev/src/serve.rs` seem to build the
website bu parsing markdown without resolving intra-doc links. So, these
lint docs need to write full URLs.

This branch has not been deployed

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

Labels

needs-fcp PRs that add, remove, or rename lints and need an FCP S-waiting-on-review Status: Awaiting review from the assignee but also interested parties

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add cargo fix support for switching to intra-doc links Lint hand-written intra-rustdoc links

5 participants