-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Improve handling of rustdoc lints when used with raw doc fragments. #136400
Open
lolbinarycat
wants to merge
5
commits into
rust-lang:master
Choose a base branch
from
lolbinarycat:rustdoc-link-lint-135851
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
791f92c
don't emit suggestion if link cannot be located
lolbinarycat c802255
add another heirustic to source_span_for_markdown_range
lolbinarycat 1b359d7
clarify doc comment on `source_span_for_markdown_range`
lolbinarycat fc86385
bless more tests
lolbinarycat c6d7696
handle more edge cases
lolbinarycat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
//@ check-fail | ||
|
||
#![deny(rustdoc::bare_urls)] | ||
|
||
// examples of bare urls that are beyond our ability to generate suggestions for | ||
|
||
// this falls through every heirustic in `source_span_for_markdown_range`, | ||
// and thus does not get any suggestion. | ||
#[doc = "good: <https://example.com/> \n\n"] | ||
//~^ ERROR this URL is not a hyperlink | ||
#[doc = "bad: https://example.com/"] | ||
pub fn duplicate_raw() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
error: this URL is not a hyperlink | ||
--> $DIR/bare-urls-limit.rs:9:9 | ||
| | ||
LL | #[doc = "good: <https://example.com/> \n\n"] | ||
| _________^ | ||
LL | | | ||
LL | | #[doc = "bad: https://example.com/"] | ||
| |___________________________________^ | ||
| | ||
= note: bare URLs are not automatically turned into clickable links | ||
note: the lint level is defined here | ||
--> $DIR/bare-urls-limit.rs:3:9 | ||
| | ||
LL | #![deny(rustdoc::bare_urls)] | ||
| ^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 1 previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
source_span_to_markdown_range
is? for what purpose?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i just checked every usage of this function in this repo, and they're all in rustdoc lints
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, that's odd.
source_span_to_markdown_range
is indeed not used in the compiler. It should be part of rustdoc instead (it doesn't rely on any compiler-internal APIs, so that would technically work) — except that this situation is slightly suspicious. Maybe it used to be used by the compiler in the past, we need to check the history. Also, it might indicate that whoever uses that function doesn't handle cross-crate intra-doc links correctly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i feel like i'm missing something, i don't see how intra-doc lints are relevant here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If something is not used in the compiler, then it should not live in
compiler/rustc_resolve
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you want me to move it in this PR, or can it be done in a followup?