Add run-rustfix for precedence test

This commit is contained in:
Wilco Kusee 2019-01-13 14:24:21 +01:00
parent 95f2a9dbfc
commit 6f17635f94
3 changed files with 52 additions and 13 deletions

37
tests/ui/precedence.fixed Normal file
View File

@ -0,0 +1,37 @@
// run-rustfix
#![warn(clippy::precedence)]
#![allow(unused_must_use, clippy::no_effect, clippy::unnecessary_operation)]
#![allow(clippy::identity_op)]
#![allow(clippy::eq_op)]
macro_rules! trip {
($a:expr) => {
match $a & 0b1111_1111u8 {
0 => println!("a is zero ({})", $a),
_ => println!("a is {}", $a),
}
};
}
fn main() {
1 << (2 + 3);
(1 + 2) << 3;
4 >> (1 + 1);
(1 + 3) >> 2;
1 ^ (1 - 1);
3 | (2 - 1);
3 & (5 - 2);
-(1i32.abs());
-(1f32.abs());
// These should not trigger an error
let _ = (-1i32).abs();
let _ = (-1f32).abs();
let _ = -(1i32).abs();
let _ = -(1f32).abs();
let _ = -(1i32.abs());
let _ = -(1f32.abs());
let b = 3;
trip!(b * 8);
}

View File

@ -1,10 +1,12 @@
#[warn(clippy::precedence)]
#[allow(clippy::identity_op)]
#[allow(clippy::eq_op)]
// run-rustfix
#![warn(clippy::precedence)]
#![allow(unused_must_use, clippy::no_effect, clippy::unnecessary_operation)]
#![allow(clippy::identity_op)]
#![allow(clippy::eq_op)]
macro_rules! trip {
($a:expr) => {
match $a & 0b1111_1111i8 {
match $a & 0b1111_1111u8 {
0 => println!("a is zero ({})", $a),
_ => println!("a is {}", $a),
}

View File

@ -1,5 +1,5 @@
error: operator precedence can trip the unwary
--> $DIR/precedence.rs:15:5
--> $DIR/precedence.rs:17:5
|
LL | 1 << 2 + 3;
| ^^^^^^^^^^ help: consider parenthesizing your expression: `1 << (2 + 3)`
@ -7,49 +7,49 @@ LL | 1 << 2 + 3;
= note: `-D clippy::precedence` implied by `-D warnings`
error: operator precedence can trip the unwary
--> $DIR/precedence.rs:16:5
--> $DIR/precedence.rs:18:5
|
LL | 1 + 2 << 3;
| ^^^^^^^^^^ help: consider parenthesizing your expression: `(1 + 2) << 3`
error: operator precedence can trip the unwary
--> $DIR/precedence.rs:17:5
--> $DIR/precedence.rs:19:5
|
LL | 4 >> 1 + 1;
| ^^^^^^^^^^ help: consider parenthesizing your expression: `4 >> (1 + 1)`
error: operator precedence can trip the unwary
--> $DIR/precedence.rs:18:5
--> $DIR/precedence.rs:20:5
|
LL | 1 + 3 >> 2;
| ^^^^^^^^^^ help: consider parenthesizing your expression: `(1 + 3) >> 2`
error: operator precedence can trip the unwary
--> $DIR/precedence.rs:19:5
--> $DIR/precedence.rs:21:5
|
LL | 1 ^ 1 - 1;
| ^^^^^^^^^ help: consider parenthesizing your expression: `1 ^ (1 - 1)`
error: operator precedence can trip the unwary
--> $DIR/precedence.rs:20:5
--> $DIR/precedence.rs:22:5
|
LL | 3 | 2 - 1;
| ^^^^^^^^^ help: consider parenthesizing your expression: `3 | (2 - 1)`
error: operator precedence can trip the unwary
--> $DIR/precedence.rs:21:5
--> $DIR/precedence.rs:23:5
|
LL | 3 & 5 - 2;
| ^^^^^^^^^ help: consider parenthesizing your expression: `3 & (5 - 2)`
error: unary minus has lower precedence than method call
--> $DIR/precedence.rs:22:5
--> $DIR/precedence.rs:24:5
|
LL | -1i32.abs();
| ^^^^^^^^^^^ help: consider adding parentheses to clarify your intent: `-(1i32.abs())`
error: unary minus has lower precedence than method call
--> $DIR/precedence.rs:23:5
--> $DIR/precedence.rs:25:5
|
LL | -1f32.abs();
| ^^^^^^^^^^^ help: consider adding parentheses to clarify your intent: `-(1f32.abs())`