Skip to content

Commit 75e694d

Browse files
committed
Improve filtering and account for spacing
1 parent af51bb8 commit 75e694d

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

clippy_lints/src/doc/needless_doctest_main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ pub fn check(
134134
//
135135
// Also, as we only check for attribute names and don't do macro expansion,
136136
// we can check only for #[test]
137-
if !(text.contains("fn main") || text.contains("#[test]")) {
137+
138+
if !((text.contains(" main") && text.splitn(2, "fn ").nth(2).is_none()) || text.contains("#[test]")) {
138139
return;
139140
}
140141

tests/ui/doc/needless_doctest_main.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,14 @@ fn lumpimupli() {}
8282
/// ```
8383
fn mpulpilumi() {}
8484

85+
#[rustfmt::skip]
86+
/// Spaces in weird positions
87+
/// ```rust
88+
/// fn main (){
89+
//~^ error: needless `fn main` in doctest
90+
/// let _ = 0;
91+
/// }
92+
/// ```
93+
fn plumpiplupi() {}
94+
8595
fn main() {}

tests/ui/doc/needless_doctest_main.stderr

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,15 @@ LL | | /// let _ = 0;
2222
LL | | /// }
2323
| |_____^
2424

25-
error: aborting due to 2 previous errors
25+
error: needless `fn main` in doctest
26+
--> tests/ui/doc/needless_doctest_main.rs:88:5
27+
|
28+
LL | /// fn main (){
29+
| _____^
30+
LL | |
31+
LL | | /// let _ = 0;
32+
LL | | /// }
33+
| |_____^
34+
35+
error: aborting due to 3 previous errors
2636

0 commit comments

Comments
 (0)