Skip to content

Commit 67c84ae

Browse files
committed
Rework the suspicious formatting lints.
1 parent fe0912a commit 67c84ae

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
@@ -1176,6 +1176,10 @@ pub trait StrExt {
11761176
where
11771177
P: Pattern,
11781178
for<'a> P::Searcher<'a>: ReverseSearcher<'a>;
1179+
1180+
/// Splits a string into a prefix and everything proceeding it. Returns `None` if the string
1181+
/// doesn't start with the prefix.
1182+
fn split_multipart_prefix(&self, pats: impl IntoIterator<Item: Pattern>) -> Option<[&Self; 2]>;
11791183
}
11801184
impl StrExt for str {
11811185
fn find_bounded_inclusive(&self, pat: impl Pattern) -> Option<&Self> {
@@ -1215,6 +1219,16 @@ impl StrExt for str {
12151219
{
12161220
self.strip_suffix(pat).map(|rest| [rest, &self[rest.len()..]])
12171221
}
1222+
1223+
/// Splits a string into a prefix and everything proceeding it. Returns `None` if the string
1224+
/// doesn't start with the prefix.
1225+
fn split_multipart_prefix(&self, pats: impl IntoIterator<Item: Pattern>) -> Option<[&Self; 2]> {
1226+
let mut s = self;
1227+
for pat in pats {
1228+
s = s.strip_prefix(pat)?;
1229+
}
1230+
Some([&self[..self.len() - s.len()], s])
1231+
}
12181232
}
12191233

12201234
/// 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)