Skip to content

Commit 06def10

Browse files
committed
Rework the suspicious formatting lints.
1 parent 51934e2 commit 06def10

24 files changed

+1636
-520
lines changed

clippy_lints/src/formatting.rs

Lines changed: 261 additions & 158 deletions
Large diffs are not rendered by default.

clippy_utils/src/source.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,6 +1346,10 @@ pub trait StrExt {
13461346
where
13471347
P: Pattern,
13481348
for<'a> P::Searcher<'a>: ReverseSearcher<'a>;
1349+
1350+
/// Splits a string into a prefix and everything proceeding it. Returns `None` if the string
1351+
/// doesn't start with the prefix.
1352+
fn split_multipart_prefix(&self, pats: impl IntoIterator<Item: Pattern>) -> Option<[&Self; 2]>;
13491353
}
13501354
impl StrExt for str {
13511355
fn find_bounded_inclusive(&self, pat: impl Pattern) -> Option<&Self> {
@@ -1387,6 +1391,16 @@ impl StrExt for str {
13871391
{
13881392
self.strip_suffix(pat).map(|rest| [rest, &self[rest.len()..]])
13891393
}
1394+
1395+
/// Splits a string into a prefix and everything proceeding it. Returns `None` if the string
1396+
/// doesn't start with the prefix.
1397+
fn split_multipart_prefix(&self, pats: impl IntoIterator<Item: Pattern>) -> Option<[&Self; 2]> {
1398+
let mut s = self;
1399+
for pat in pats {
1400+
s = s.strip_prefix(pat)?;
1401+
}
1402+
Some([&self[..self.len() - s.len()], s])
1403+
}
13901404
}
13911405

13921406
/// Checks if the last token of the string is either a line comment or an incomplete token.

tests/ui/formatting.rs

Lines changed: 0 additions & 88 deletions
This file was deleted.

tests/ui/formatting.stderr

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
//@aux-build:../auxiliary/proc_macros.rs
2+
#![deny(clippy::possible_missing_comma)]
3+
4+
use proc_macros::{external, inline_macros, with_span};
5+
6+
#[rustfmt::skip]
7+
#[inline_macros]
8+
fn main() {
9+
{
10+
let x = 20;
11+
let y = &32;
12+
13+
let _ = [1, 2, *y]; //~ possible_missing_comma
14+
let _ = [1, 2, -x]; //~ possible_missing_comma
15+
let _ = [1, x - 2, -x]; //~ possible_missing_comma
16+
let _ = [1, 2, -x - 2]; //~ possible_missing_comma
17+
let _ = [1, 2 * x * 2, -x]; //~ possible_missing_comma
18+
19+
let _ = [
20+
1,
21+
x,
22+
-2 * x * 2, //~ possible_missing_comma
23+
-x, //~ possible_missing_comma
24+
];
25+
26+
let _ = (1, &x); //~ possible_missing_comma
27+
let _ = (1, x, -1); //~ possible_missing_comma
28+
29+
let _ = (1-x);
30+
let _ = (1- x);
31+
let _ = (1 -/* comment */x);
32+
let _ = (1, 2*y - 5);
33+
let _ = (1, 2 /x);
34+
let _ = (1, 2 <x);
35+
let _ = (1, 2 !=x);
36+
let _ = (1, 2 |x);
37+
let _ = (1, 2 <<x);
38+
39+
let _ = [
40+
1
41+
- x,
42+
x
43+
* y,
44+
];
45+
}
46+
47+
{
48+
let x = true;
49+
let y = false;
50+
51+
let _ = (y, &&x); //~ possible_missing_comma
52+
let _ = (y && x);
53+
let _ = (y&&x);
54+
}
55+
56+
with_span! {
57+
span
58+
let x = 0;
59+
let _ = (x -1);
60+
}
61+
62+
external! {
63+
let x = 0;
64+
let _ = (x -1);
65+
}
66+
67+
inline! {
68+
let x = 0;
69+
let _ = (x, -1); //~ possible_missing_comma
70+
let _ = (x, -$(@tt 1)); //~ possible_missing_comma
71+
let _ = ($(@expr x -1));
72+
let _ = (x $(@tt -)1);
73+
}
74+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
//@aux-build:../auxiliary/proc_macros.rs
2+
#![deny(clippy::possible_missing_comma)]
3+
4+
use proc_macros::{external, inline_macros, with_span};
5+
6+
#[rustfmt::skip]
7+
#[inline_macros]
8+
fn main() {
9+
{
10+
let x = 20;
11+
let y = &32;
12+
13+
let _ = [1, 2 * y]; //~ possible_missing_comma
14+
let _ = [1, 2 - x]; //~ possible_missing_comma
15+
let _ = [1, x - 2 - x]; //~ possible_missing_comma
16+
let _ = [1, 2 - x - 2]; //~ possible_missing_comma
17+
let _ = [1, 2 * x * 2 - x]; //~ possible_missing_comma
18+
19+
let _ = [
20+
1,
21+
x
22+
- 2 * x * 2 //~ possible_missing_comma
23+
- x, //~ possible_missing_comma
24+
];
25+
26+
let _ = (1 & x); //~ possible_missing_comma
27+
let _ = (1, x - 1); //~ possible_missing_comma
28+
29+
let _ = (1-x);
30+
let _ = (1- x);
31+
let _ = (1 -/* comment */x);
32+
let _ = (1, 2*y - 5);
33+
let _ = (1, 2 /x);
34+
let _ = (1, 2 <x);
35+
let _ = (1, 2 !=x);
36+
let _ = (1, 2 |x);
37+
let _ = (1, 2 <<x);
38+
39+
let _ = [
40+
1
41+
- x,
42+
x
43+
* y,
44+
];
45+
}
46+
47+
{
48+
let x = true;
49+
let y = false;
50+
51+
let _ = (y && x); //~ possible_missing_comma
52+
let _ = (y && x);
53+
let _ = (y&&x);
54+
}
55+
56+
with_span! {
57+
span
58+
let x = 0;
59+
let _ = (x -1);
60+
}
61+
62+
external! {
63+
let x = 0;
64+
let _ = (x -1);
65+
}
66+
67+
inline! {
68+
let x = 0;
69+
let _ = (x - 1); //~ possible_missing_comma
70+
let _ = (x - $(@tt 1)); //~ possible_missing_comma
71+
let _ = ($(@expr x -1));
72+
let _ = (x $(@tt -)1);
73+
}
74+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
//@aux-build:../auxiliary/proc_macros.rs
2+
#![deny(clippy::possible_missing_comma)]
3+
4+
use proc_macros::{external, inline_macros, with_span};
5+
6+
#[rustfmt::skip]
7+
#[inline_macros]
8+
fn main() {
9+
{
10+
let x = 20;
11+
let y = &32;
12+
13+
let _ = [1, 2 *y]; //~ possible_missing_comma
14+
let _ = [1, 2 -x]; //~ possible_missing_comma
15+
let _ = [1, x - 2 -x]; //~ possible_missing_comma
16+
let _ = [1, 2 -x - 2]; //~ possible_missing_comma
17+
let _ = [1, 2 * x * 2 -x]; //~ possible_missing_comma
18+
19+
let _ = [
20+
1,
21+
x
22+
-2 * x * 2 //~ possible_missing_comma
23+
-x, //~ possible_missing_comma
24+
];
25+
26+
let _ = (1 &x); //~ possible_missing_comma
27+
let _ = (1, x -1); //~ possible_missing_comma
28+
29+
let _ = (1-x);
30+
let _ = (1- x);
31+
let _ = (1 -/* comment */x);
32+
let _ = (1, 2*y - 5);
33+
let _ = (1, 2 /x);
34+
let _ = (1, 2 <x);
35+
let _ = (1, 2 !=x);
36+
let _ = (1, 2 |x);
37+
let _ = (1, 2 <<x);
38+
39+
let _ = [
40+
1
41+
- x,
42+
x
43+
* y,
44+
];
45+
}
46+
47+
{
48+
let x = true;
49+
let y = false;
50+
51+
let _ = (y &&x); //~ possible_missing_comma
52+
let _ = (y && x);
53+
let _ = (y&&x);
54+
}
55+
56+
with_span! {
57+
span
58+
let x = 0;
59+
let _ = (x -1);
60+
}
61+
62+
external! {
63+
let x = 0;
64+
let _ = (x -1);
65+
}
66+
67+
inline! {
68+
let x = 0;
69+
let _ = (x -1); //~ possible_missing_comma
70+
let _ = (x -$(@tt 1)); //~ possible_missing_comma
71+
let _ = ($(@expr x -1));
72+
let _ = (x $(@tt -)1);
73+
}
74+
}

0 commit comments

Comments
 (0)