Skip to content

Commit f543c33

Browse files
doc_comments_missing_terminal_punctuation: handle code spans properly
1 parent 52c74f6 commit f543c33

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

clippy_lints/src/doc/doc_comments_missing_terminal_punctuation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ fn is_missing_punctuation(doc_string: &str) -> Option<usize> {
6262
Event::Start(Tag::Link { .. }) | Event::End(TagEnd::Link) if no_report_depth == 0 && !offset.is_empty() => {
6363
text_offset = Some(offset.end);
6464
},
65-
Event::Text(..) if no_report_depth == 0 && !offset.is_empty() => {
65+
Event::Code(..) | Event::Text(..) if no_report_depth == 0 && !offset.is_empty() => {
6666
if doc_string[..offset.end].trim_end().ends_with(')') {
6767
text_offset = Some(offset.end - 1);
6868
} else {

tests/ui/doc/doc_comments_missing_terminal_punctuation.fixed

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ struct OnlyLastSentence;
141141
/// ```
142142
struct IncompleteBlockCode;
143143

144+
/// This ends with a code `span`.
145+
//~^ doc_comments_missing_terminal_punctuation
146+
struct CodeSpan;
147+
144148
#[expect(clippy::empty_docs)]
145149
///
146150
struct EmptyDocComment;

tests/ui/doc/doc_comments_missing_terminal_punctuation.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ struct OnlyLastSentence;
141141
/// ```
142142
struct IncompleteBlockCode;
143143

144+
/// This ends with a code `span`
145+
//~^ doc_comments_missing_terminal_punctuation
146+
struct CodeSpan;
147+
144148
#[expect(clippy::empty_docs)]
145149
///
146150
struct EmptyDocComment;

tests/ui/doc/doc_comments_missing_terminal_punctuation.stderr

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,16 @@ LL | /// Only the last sentence is
8686
| ^ help: end the doc comment with some punctuation: `.`
8787

8888
error: doc comments should end with a terminal punctuation mark
89-
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:149:27
89+
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:144:33
90+
|
91+
LL | /// This ends with a code `span`
92+
| ^ help: end the doc comment with some punctuation: `.`
93+
94+
error: doc comments should end with a terminal punctuation mark
95+
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:153:27
9096
|
9197
LL | * Block doc comments work
9298
| ^ help: end the doc comment with some punctuation: `.`
9399

94-
error: aborting due to 15 previous errors
100+
error: aborting due to 16 previous errors
95101

0 commit comments

Comments
 (0)