Skip to content

Commit 6f17635

Browse files
committed
Add run-rustfix for precedence test
1 parent 95f2a9d commit 6f17635

File tree

3 files changed

+52
-13
lines changed

3 files changed

+52
-13
lines changed

tests/ui/precedence.fixed

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// run-rustfix
2+
#![warn(clippy::precedence)]
3+
#![allow(unused_must_use, clippy::no_effect, clippy::unnecessary_operation)]
4+
#![allow(clippy::identity_op)]
5+
#![allow(clippy::eq_op)]
6+
7+
macro_rules! trip {
8+
($a:expr) => {
9+
match $a & 0b1111_1111u8 {
10+
0 => println!("a is zero ({})", $a),
11+
_ => println!("a is {}", $a),
12+
}
13+
};
14+
}
15+
16+
fn main() {
17+
1 << (2 + 3);
18+
(1 + 2) << 3;
19+
4 >> (1 + 1);
20+
(1 + 3) >> 2;
21+
1 ^ (1 - 1);
22+
3 | (2 - 1);
23+
3 & (5 - 2);
24+
-(1i32.abs());
25+
-(1f32.abs());
26+
27+
// These should not trigger an error
28+
let _ = (-1i32).abs();
29+
let _ = (-1f32).abs();
30+
let _ = -(1i32).abs();
31+
let _ = -(1f32).abs();
32+
let _ = -(1i32.abs());
33+
let _ = -(1f32.abs());
34+
35+
let b = 3;
36+
trip!(b * 8);
37+
}

tests/ui/precedence.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
#[warn(clippy::precedence)]
2-
#[allow(clippy::identity_op)]
3-
#[allow(clippy::eq_op)]
1+
// run-rustfix
2+
#![warn(clippy::precedence)]
3+
#![allow(unused_must_use, clippy::no_effect, clippy::unnecessary_operation)]
4+
#![allow(clippy::identity_op)]
5+
#![allow(clippy::eq_op)]
46

57
macro_rules! trip {
68
($a:expr) => {
7-
match $a & 0b1111_1111i8 {
9+
match $a & 0b1111_1111u8 {
810
0 => println!("a is zero ({})", $a),
911
_ => println!("a is {}", $a),
1012
}

tests/ui/precedence.stderr

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,55 @@
11
error: operator precedence can trip the unwary
2-
--> $DIR/precedence.rs:15:5
2+
--> $DIR/precedence.rs:17:5
33
|
44
LL | 1 << 2 + 3;
55
| ^^^^^^^^^^ help: consider parenthesizing your expression: `1 << (2 + 3)`
66
|
77
= note: `-D clippy::precedence` implied by `-D warnings`
88

99
error: operator precedence can trip the unwary
10-
--> $DIR/precedence.rs:16:5
10+
--> $DIR/precedence.rs:18:5
1111
|
1212
LL | 1 + 2 << 3;
1313
| ^^^^^^^^^^ help: consider parenthesizing your expression: `(1 + 2) << 3`
1414

1515
error: operator precedence can trip the unwary
16-
--> $DIR/precedence.rs:17:5
16+
--> $DIR/precedence.rs:19:5
1717
|
1818
LL | 4 >> 1 + 1;
1919
| ^^^^^^^^^^ help: consider parenthesizing your expression: `4 >> (1 + 1)`
2020

2121
error: operator precedence can trip the unwary
22-
--> $DIR/precedence.rs:18:5
22+
--> $DIR/precedence.rs:20:5
2323
|
2424
LL | 1 + 3 >> 2;
2525
| ^^^^^^^^^^ help: consider parenthesizing your expression: `(1 + 3) >> 2`
2626

2727
error: operator precedence can trip the unwary
28-
--> $DIR/precedence.rs:19:5
28+
--> $DIR/precedence.rs:21:5
2929
|
3030
LL | 1 ^ 1 - 1;
3131
| ^^^^^^^^^ help: consider parenthesizing your expression: `1 ^ (1 - 1)`
3232

3333
error: operator precedence can trip the unwary
34-
--> $DIR/precedence.rs:20:5
34+
--> $DIR/precedence.rs:22:5
3535
|
3636
LL | 3 | 2 - 1;
3737
| ^^^^^^^^^ help: consider parenthesizing your expression: `3 | (2 - 1)`
3838

3939
error: operator precedence can trip the unwary
40-
--> $DIR/precedence.rs:21:5
40+
--> $DIR/precedence.rs:23:5
4141
|
4242
LL | 3 & 5 - 2;
4343
| ^^^^^^^^^ help: consider parenthesizing your expression: `3 & (5 - 2)`
4444

4545
error: unary minus has lower precedence than method call
46-
--> $DIR/precedence.rs:22:5
46+
--> $DIR/precedence.rs:24:5
4747
|
4848
LL | -1i32.abs();
4949
| ^^^^^^^^^^^ help: consider adding parentheses to clarify your intent: `-(1i32.abs())`
5050

5151
error: unary minus has lower precedence than method call
52-
--> $DIR/precedence.rs:23:5
52+
--> $DIR/precedence.rs:25:5
5353
|
5454
LL | -1f32.abs();
5555
| ^^^^^^^^^^^ help: consider adding parentheses to clarify your intent: `-(1f32.abs())`

0 commit comments

Comments
 (0)