Skip to content

Commit 2ad3520

Browse files
committed
fix: too_long_first_doc_paragraph suggests wrongly when first line too long
1 parent e479a9f commit 2ad3520

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

clippy_lints/src/doc/too_long_first_doc_paragraph.rs

+4
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ pub(super) fn check(
5151
// We make this suggestion only if the first doc line ends with a punctuation
5252
// because it might just need to add an empty line with `///`.
5353
should_suggest_empty_doc = doc.ends_with('.') || doc.ends_with('!') || doc.ends_with('?');
54+
} else if spans.len() == 2 {
55+
// We make this suggestion only if the second doc line is not empty.
56+
should_suggest_empty_doc &= !doc.is_empty();
5457
}
58+
5559
let len = doc.chars().count();
5660
if len >= first_paragraph_len {
5761
break;

tests/ui/too_long_first_doc_paragraph.rs

+7
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ pub union Union2 {
6161
/// gravida non lacinia at, rhoncus eu lacus.
6262
fn f() {}
6363

64+
#[rustfmt::skip]
65+
/// Some function. This doc-string paragraph is too long. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
66+
//~^ too_long_first_doc_paragraph
67+
///
68+
/// Here's a second paragraph. It would be preferable to put the details here.
69+
pub fn issue_14274() {}
70+
6471
fn main() {
6572
// test code goes here
6673
}

tests/ui/too_long_first_doc_paragraph.stderr

+10-1
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,14 @@ LL | | /// a dolor in, pellentesque aliquet enim. Cras nec maximus sem. Mauris a
3939
LL | | /// gravida non lacinia at, rhoncus eu lacus.
4040
| |_^
4141

42-
error: aborting due to 3 previous errors
42+
error: first doc comment paragraph is too long
43+
--> tests/ui/too_long_first_doc_paragraph.rs:65:1
44+
|
45+
LL | / /// Some function. This doc-string paragraph is too long. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lore...
46+
LL | |
47+
LL | | ///
48+
LL | | /// Here's a second paragraph. It would be preferable to put the details here.
49+
| |_^
50+
51+
error: aborting due to 4 previous errors
4352

0 commit comments

Comments
 (0)