-
-
Notifications
You must be signed in to change notification settings - Fork 15.4k
rustdoc: do not include extra stuff in span #157561
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
rust-bors
merged 15 commits into
rust-lang:main
from
notriddle:do-not-destroy-function-name
Jul 10, 2026
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
84f2896
rustdoc: do not include extra stuff in span
notriddle 2001b88
Fix `unbalanced_ticks` when doc isn't contiguous
notriddle e66a504
Add test case for split missing punctuation
notriddle f7302b9
Skip the unhelpful binary search
notriddle b66a23f
Rename `span` and `line_bytes` to more specific
notriddle f93f2e4
Use an intermediate variable for readability
notriddle 7975dc7
Add clarifying comment
notriddle 4d83004
Remove unused `Option` return
notriddle 9438aac
Handle span failure in redundant_explicit_links
notriddle 74c203d
Add clarifying comment for shrink_to_hi
notriddle 162a90c
Handle block doc comments better
notriddle 042e779
Add diagram to comment
notriddle 8f1fd2c
Fix wrong diagram in comment
notriddle fd07857
Use better name for lint struct
notriddle ebe343b
Clean up redundant explicit intra-doc link
notriddle 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 hidden or 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 hidden or 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 | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -641,42 +641,99 @@ pub fn source_span_for_markdown_range_inner( | |||||||||||||||||||||||
| let mut start_bytes = 0; | ||||||||||||||||||||||||
| let mut end_bytes = 0; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| let span_of_all_fragments: Span = span_of_fragments(fragments)?; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| let mut prev_lines_bytes = 0; | ||||||||||||||||||||||||
| 'outer: for (line_no, md_line) in md_lines.enumerate() { | ||||||||||||||||||||||||
| loop { | ||||||||||||||||||||||||
| let source_line = src_lines.next()?; | ||||||||||||||||||||||||
| match source_line.find(md_line) { | ||||||||||||||||||||||||
| Some(offset) => { | ||||||||||||||||||||||||
| if line_no == starting_line { | ||||||||||||||||||||||||
| start_bytes += offset; | ||||||||||||||||||||||||
| let source_line_len = u32::try_from(source_line.len()).unwrap(); | ||||||||||||||||||||||||
| let source_line_span = | ||||||||||||||||||||||||
| span_of_all_fragments.split_at(prev_lines_bytes).1.split_at(source_line_len).0; | ||||||||||||||||||||||||
| let fragment = fragments | ||||||||||||||||||||||||
| .iter() | ||||||||||||||||||||||||
| // `source_line_span` might contain indentation that `fragment.span` doesn't contain | ||||||||||||||||||||||||
| .find(|fragment| fragment.span.overlaps(source_line_span)); | ||||||||||||||||||||||||
| // Since we're counting bytes, `prev_line_bytes` includes the "\n". | ||||||||||||||||||||||||
| prev_lines_bytes += source_line_len + 1; | ||||||||||||||||||||||||
| if let Some(fragment) = fragment | ||||||||||||||||||||||||
| && let Some(offset) = source_line.find(md_line) | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| if fragment.span.lo() > source_line_span.lo() | ||||||||||||||||||||||||
| && source_line | ||||||||||||||||||||||||
| [..usize::try_from(fragment.span.lo().0 - source_line_span.lo().0).unwrap()] | ||||||||||||||||||||||||
| .chars() | ||||||||||||||||||||||||
| .any(|c| !c.is_whitespace()) | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| // Make sure anything between the start of this line and the fragment itself is just indentation. | ||||||||||||||||||||||||
| // Because source_line is built by splitting the span that covers all fragments, this only finds | ||||||||||||||||||||||||
| // characters *between* doc comments, not characters before or after doc comments. | ||||||||||||||||||||||||
| // | ||||||||||||||||||||||||
| // 1| /** doc */ | ||||||||||||||||||||||||
| // 2| #[inline] /** doc2 */ | ||||||||||||||||||||||||
| // ^^^^^^^^^ | ||||||||||||||||||||||||
| // | this | ||||||||||||||||||||||||
| // | ||||||||||||||||||||||||
| // 3| fn foo() {} | ||||||||||||||||||||||||
| return None; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| if fragment.span.hi() < source_line_span.hi() | ||||||||||||||||||||||||
| && source_line | ||||||||||||||||||||||||
| [usize::try_from(fragment.span.hi().0 - source_line_span.lo().0).unwrap()..] | ||||||||||||||||||||||||
| .chars() | ||||||||||||||||||||||||
| .any(|c| !c.is_whitespace()) | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| // Make sure anything between the start of this line and the fragment itself is just indentation. | ||||||||||||||||||||||||
| // Because source_line is built by splitting the span that covers all fragments, this only finds | ||||||||||||||||||||||||
| // characters *between* doc comments, not characters before or after doc comments. | ||||||||||||||||||||||||
| // 1| /** doc */ #[inline] | ||||||||||||||||||||||||
| // ^^^^^^^^^ | ||||||||||||||||||||||||
| // | this | ||||||||||||||||||||||||
| // | ||||||||||||||||||||||||
| // 2| /** doc2 */ | ||||||||||||||||||||||||
| // 3| fn foo() {} | ||||||||||||||||||||||||
| return None; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| if line_no == starting_line { | ||||||||||||||||||||||||
| start_bytes += offset; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if starting_line == ending_line { | ||||||||||||||||||||||||
| break 'outer; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } else if line_no == ending_line { | ||||||||||||||||||||||||
| end_bytes += offset; | ||||||||||||||||||||||||
| if starting_line == ending_line { | ||||||||||||||||||||||||
| break 'outer; | ||||||||||||||||||||||||
| } else if line_no < starting_line { | ||||||||||||||||||||||||
| start_bytes += source_line.len() - md_line.len(); | ||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||
| end_bytes += source_line.len() - md_line.len(); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||
| } else if line_no == ending_line { | ||||||||||||||||||||||||
| end_bytes += offset; | ||||||||||||||||||||||||
| break 'outer; | ||||||||||||||||||||||||
| } else if line_no < starting_line { | ||||||||||||||||||||||||
| start_bytes += source_line.len() - md_line.len(); | ||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||
| end_bytes += source_line.len() - md_line.len(); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| None => { | ||||||||||||||||||||||||
| // Since this is a source line that doesn't include a markdown line, | ||||||||||||||||||||||||
| // we have to count the newline that we split from earlier. | ||||||||||||||||||||||||
| if line_no <= starting_line { | ||||||||||||||||||||||||
| start_bytes += source_line.len() + 1; | ||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||
| end_bytes += source_line.len() + 1; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||
| // Since this is a source line that doesn't include a markdown line, | ||||||||||||||||||||||||
| // we have to count it and its newline as non-markdown bytes. | ||||||||||||||||||||||||
| if line_no <= starting_line { | ||||||||||||||||||||||||
| start_bytes += source_line.len() + 1; | ||||||||||||||||||||||||
| } else if source_line.chars().any(|c| !c.is_whitespace()) { | ||||||||||||||||||||||||
| // We're past the first line, but haven't found the last line, | ||||||||||||||||||||||||
| // but we found a non-empty non-markdown line. | ||||||||||||||||||||||||
| // This could be an attribute, and we don't want a diagnostic | ||||||||||||||||||||||||
| // suggesting to delete that attribute, so we return None to be safe. | ||||||||||||||||||||||||
| // 1| /** doc */ | ||||||||||||||||||||||||
| // 2 | #[inline] | ||||||||||||||||||||||||
| // ^^^^^^^^^ | ||||||||||||||||||||||||
| // | this | ||||||||||||||||||||||||
| // 3| /** doc2 */ | ||||||||||||||||||||||||
| // 4| fn foo() {} | ||||||||||||||||||||||||
| return None; | ||||||||||||||||||||||||
|
Comment on lines
+717
to
+728
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||
| end_bytes += source_line.len() + 1; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| let span = span_of_fragments(fragments)?; | ||||||||||||||||||||||||
| let src_span = span.from_inner(InnerSpan::new( | ||||||||||||||||||||||||
| let src_span = span_of_all_fragments.from_inner(InnerSpan::new( | ||||||||||||||||||||||||
| md_range.start + start_bytes, | ||||||||||||||||||||||||
| md_range.end + start_bytes + end_bytes, | ||||||||||||||||||||||||
| )); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.