Skip to content

rustdoc: improve refdef handling in the unresolved link lint #136363

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

Merged

Conversation

notriddle
Copy link
Contributor

This commit takes advantage of a feature in pulldown-cmark that makes the list of link definitions available to the consuming application. It produces unresolved link warnings for refdefs that aren't used, and can now produce exact spans for the dest even when it has escapes.

Closes #133150 since this lint would have caught the mistake in that issue, and, along with rust-lang/rust-clippy#13707, most mistakes in this class should produce a warning from one of them.

@rustbot
Copy link
Collaborator

rustbot commented Jan 31, 2025

r? @fmease

rustbot has assigned @fmease.
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

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Jan 31, 2025
Comment on lines -126 to -127
/// The [cln][] link here is going to be unresolved, because `struct@Clone` gets //~ERROR link
/// rejected in Markdown for not being URL-shaped enough.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This comment was wrong.

struct@Clone is URL-ish enough to match CommonMark's refdef grammar. The reason it was rejected before was because the //~ERROR link hot comment got fed to the markdown parser, and, as a result, caused the refdef to not get parsed there.

By using a below-the-line comment, I can work around that and demonstrate the change correctly.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@notriddle notriddle force-pushed the notriddle/unresolved-link-unused-refdef branch from 27c6b66 to d15dfe7 Compare January 31, 2025 22:22

links.push(preprocess_link(&dest_url));
}
_ => {}
}
}

for (label, refdef) in event_iter.reference_definitions().iter() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This logic is run on a compiler's happy path, when rustdoc and its lints are not involved.
Could you do a perf run before merging this?

@notriddle
Copy link
Contributor Author

Not a problem.

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 3, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 3, 2025
…unused-refdef, r=<try>

rustdoc: improve refdef handling in the unresolved link lint

This commit takes advantage of a feature in pulldown-cmark that makes the list of link definitions available to the consuming application. It produces unresolved link warnings for refdefs that aren't used, and can now produce exact spans for the dest even when it has escapes.

Closes rust-lang#133150 since this lint would have caught the mistake in that issue, and, along with rust-lang/rust-clippy#13707, most mistakes in this class should produce a warning from one of them.
@bors
Copy link
Collaborator

bors commented Feb 3, 2025

⌛ Trying commit d15dfe7 with merge 230bb73...

@bors
Copy link
Collaborator

bors commented Feb 3, 2025

☀️ Try build successful - checks-actions
Build commit: 230bb73 (230bb733f167bb2561c8450c5669374b46ef4209)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (230bb73): comparison URL.

Overall result: ❌ regressions - no action needed

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
0.2% [0.2%, 0.2%] 2
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.2% [0.2%, 0.2%] 2

Max RSS (memory usage)

Results (primary -1.6%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.6% [-1.6%, -1.6%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -1.6% [-1.6%, -1.6%] 1

Cycles

Results (primary -2.1%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.1% [-2.1%, -2.1%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -2.1% [-2.1%, -2.1%] 1

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 779.425s -> 779.101s (-0.04%)
Artifact size: 328.79 MiB -> 328.83 MiB (0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 4, 2025
@notriddle
Copy link
Contributor Author

The two regressions are both doc builds, tiny, and they come with a diagnostic that can help people out of a pretty bad syntax hole.

@notriddle
Copy link
Contributor Author

r? @GuillaumeGomez

@rustbot rustbot assigned GuillaumeGomez and unassigned fmease Feb 14, 2025
@GuillaumeGomez
Copy link
Member

It's really cool, great idea! Perf impact seems acceptable to me. Not sure if we are waiting on petrochenkov or not so I'll let you r+.

@notriddle
Copy link
Contributor Author

This logic is run on a compiler's happy path, when rustdoc and its lints are not involved.
Could you do a perf run before merging this?

The result of the lint is no perf impacts other than rustdoc, so it shouldn't be a problem.

@bors r=GuillaumeGomez

@bors
Copy link
Collaborator

bors commented Feb 14, 2025

📌 Commit d15dfe7 has been approved by GuillaumeGomez

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 14, 2025
@bors
Copy link
Collaborator

bors commented Feb 14, 2025

⌛ Testing commit d15dfe7 with merge c3a99e7...

@bors
Copy link
Collaborator

bors commented Feb 14, 2025

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 14, 2025
@rust-log-analyzer

This comment has been minimized.

@fmease
Copy link
Member

fmease commented Feb 14, 2025

@bors retry (after #137041)

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 14, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 15, 2025
…unused-refdef, r=GuillaumeGomez

rustdoc: improve refdef handling in the unresolved link lint

This commit takes advantage of a feature in pulldown-cmark that makes the list of link definitions available to the consuming application. It produces unresolved link warnings for refdefs that aren't used, and can now produce exact spans for the dest even when it has escapes.

Closes rust-lang#133150 since this lint would have caught the mistake in that issue, and, along with rust-lang/rust-clippy#13707, most mistakes in this class should produce a warning from one of them.
@bors
Copy link
Collaborator

bors commented Feb 15, 2025

⌛ Testing commit d15dfe7 with merge bd3b5cb...

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Feb 15, 2025

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 15, 2025
This commit takes advantage of a feature in pulldown-cmark that
makes the list of link definitions available to the consuming
application. It produces unresolved link warnings for refdefs
that aren't used, and can now produce exact spans for the dest
even when it has escapes.
@notriddle notriddle force-pushed the notriddle/unresolved-link-unused-refdef branch from d15dfe7 to 4d551dd Compare February 15, 2025 19:23
@rustbot rustbot added the T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. label Feb 15, 2025
@notriddle
Copy link
Contributor Author

Rebased it. This change required weird-syntax.stderr to be re-blessed because of a minor output change:

- LL | /// [cln]: trait@Clone
-    |            ~~~~~~
+ LL - /// [cln]: struct@Clone
+ LL + /// [cln]: trait@Clone

@bors r=GuillaumeGomez

@bors
Copy link
Collaborator

bors commented Feb 15, 2025

📌 Commit 4d551dd has been approved by GuillaumeGomez

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 15, 2025
@bors
Copy link
Collaborator

bors commented Feb 16, 2025

⌛ Testing commit 4d551dd with merge 23032f3...

@bors
Copy link
Collaborator

bors commented Feb 16, 2025

☀️ Test successful - checks-actions
Approved by: GuillaumeGomez
Pushing 23032f3 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Feb 16, 2025
@bors bors merged commit 23032f3 into rust-lang:master Feb 16, 2025
7 checks passed
@rustbot rustbot added this to the 1.87.0 milestone Feb 16, 2025
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (23032f3): comparison URL.

Overall result: ❌ regressions - no action needed

@rustbot label: -perf-regression

Instruction count

This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
0.3% [0.2%, 0.3%] 2
Regressions ❌
(secondary)
0.2% [0.2%, 0.2%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.3% [0.2%, 0.3%] 2

Max RSS (memory usage)

This benchmark run did not return any relevant results for this metric.

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 790.759s -> 789.651s (-0.14%)
Artifact size: 350.03 MiB -> 350.07 MiB (0.01%)

@notriddle notriddle deleted the notriddle/unresolved-link-unused-refdef branch February 17, 2025 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rustdoc skips first line of some list items, and incorrect clippy warning
8 participants