Skip to content

Commit 2b7d80b

Browse files
committed
Auto merge of rust-lang#13377 - vHugoObject:master, r=dswij
fix: Fixed incorrect comment form suggestion for too_long_first_doc_paragraph lint fixes rust-lang#13309 changelog: none Comment form is now a variable and a new test for too_long_first_doc_paragraph was added.
2 parents eb5d4b7 + d66e9ad commit 2b7d80b

File tree

3 files changed

+40
-7
lines changed

3 files changed

+40
-7
lines changed

clippy_lints/src/doc/too_long_first_doc_paragraph.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,17 @@ pub(super) fn check(
7979
&& let new_span = first_span.with_hi(second_span.lo()).with_lo(first_span.hi())
8080
&& let Some(snippet) = snippet_opt(cx, new_span)
8181
{
82+
let Some(first) = snippet_opt(cx, first_span) else {
83+
return;
84+
};
85+
let Some(comment_form) = first.get(..3) else {
86+
return;
87+
};
88+
8289
diag.span_suggestion(
8390
new_span,
8491
"add an empty line",
85-
format!("{snippet}///\n"),
92+
format!("{snippet}{comment_form}{snippet}"),
8693
Applicability::MachineApplicable,
8794
);
8895
}

tests/ui/too_long_first_doc_paragraph.rs

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
#![warn(clippy::too_long_first_doc_paragraph)]
44

5+
pub mod foo {
6+
7+
// in foo.rs
8+
//! A very short summary.
9+
//! A much longer explanation that goes into a lot more detail about
10+
//! how the thing works, possibly with doclinks and so one,
11+
//! and probably spanning a many rows. Blablabla, it needs to be over
12+
//! 200 characters so I needed to write something longeeeeeeer.
13+
}
14+
515
/// Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc turpis nunc, lacinia
616
/// a dolor in, pellentesque aliquet enim. Cras nec maximus sem. Mauris arcu libero,
717
/// gravida non lacinia at, rhoncus eu lacus.
+22-6
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,38 @@
11
error: first doc comment paragraph is too long
2-
--> tests/ui/too_long_first_doc_paragraph.rs:5:1
2+
--> tests/ui/too_long_first_doc_paragraph.rs:8:5
3+
|
4+
LL | / //! A very short summary.
5+
LL | | //! A much longer explanation that goes into a lot more detail about
6+
LL | | //! how the thing works, possibly with doclinks and so one,
7+
LL | | //! and probably spanning a many rows. Blablabla, it needs to be over
8+
LL | | //! 200 characters so I needed to write something longeeeeeeer.
9+
| |____^
10+
|
11+
= note: `-D clippy::too-long-first-doc-paragraph` implied by `-D warnings`
12+
= help: to override `-D warnings` add `#[allow(clippy::too_long_first_doc_paragraph)]`
13+
help: add an empty line
14+
|
15+
LL ~ //! A very short summary.
16+
LL + //!
17+
LL ~ //! A much longer explanation that goes into a lot more detail about
18+
|
19+
20+
error: first doc comment paragraph is too long
21+
--> tests/ui/too_long_first_doc_paragraph.rs:15:1
322
|
423
LL | / /// Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc turpis nunc, lacinia
524
LL | | /// a dolor in, pellentesque aliquet enim. Cras nec maximus sem. Mauris arcu libero,
625
LL | | /// gravida non lacinia at, rhoncus eu lacus.
726
| |_
8-
|
9-
= note: `-D clippy::too-long-first-doc-paragraph` implied by `-D warnings`
10-
= help: to override `-D warnings` add `#[allow(clippy::too_long_first_doc_paragraph)]`
1127

1228
error: first doc comment paragraph is too long
13-
--> tests/ui/too_long_first_doc_paragraph.rs:26:1
29+
--> tests/ui/too_long_first_doc_paragraph.rs:36:1
1430
|
1531
LL | / /// Lorem
1632
LL | | /// ipsum dolor sit amet, consectetur adipiscing elit. Nunc turpis nunc, lacinia
1733
LL | | /// a dolor in, pellentesque aliquet enim. Cras nec maximus sem. Mauris arcu libero,
1834
LL | | /// gravida non lacinia at, rhoncus eu lacus.
1935
| |_
2036

21-
error: aborting due to 2 previous errors
37+
error: aborting due to 3 previous errors
2238

0 commit comments

Comments
 (0)