Skip to content

Commit 953e2c5

Browse files
committed
Rework the suspicious formatting lints.
1 parent b89b849 commit 953e2c5

24 files changed

+1641
-521
lines changed

clippy_lints/src/formatting.rs

Lines changed: 246 additions & 159 deletions
Large diffs are not rendered by default.

clippy_utils/src/source.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,40 @@ impl<'sm> SourceFileRange<'sm> {
510510
self
511511
}
512512

513+
/// Sets the current range to the range between the current range and the given range.
514+
/// Does nothing and returns `None` if the ranges overlap.
515+
///
516+
/// With debug assertions enabled this will assert that the given range:
517+
/// * Is within the same file as the current range.
518+
/// * Lies on a UTF-8 boundary.
519+
#[inline]
520+
#[must_use]
521+
#[cfg_attr(debug_assertions, track_caller)]
522+
pub fn set_range_between_other(&mut self, other: impl SpanLike) -> Option<&mut Self> {
523+
fn f<'a, 'sm>(
524+
self_: &'a mut SourceFileRange<'sm>,
525+
other: Range<BytePos>,
526+
) -> Option<&'a mut SourceFileRange<'sm>> {
527+
let file = self_.file();
528+
let other = other.into_range();
529+
let other: Range<RelativeBytePos> = RelativeBytePos(other.start.0.wrapping_sub(file.start_pos.0))
530+
..RelativeBytePos(other.end.0.wrapping_sub(file.start_pos.0));
531+
dbg_check_range(self_, other.clone());
532+
if self_.range.end.0.cast_signed() < other.start.0.cast_signed() {
533+
self_.range.start = self_.range.end;
534+
self_.range.end = other.start;
535+
Some(self_)
536+
} else if self_.range.start.0.cast_signed() > other.end.0.cast_signed() {
537+
self_.range.end = self_.range.start;
538+
self_.range.start = other.end;
539+
Some(self_)
540+
} else {
541+
None
542+
}
543+
}
544+
f(self, other.into_range())
545+
}
546+
513547
/// Sets the start of this range to the given source map position if it's at or before
514548
/// the current range.
515549
///

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+
}

0 commit comments

Comments
 (0)