Skip to content

Commit

Permalink
Separate tests into fixable and unfixable
Browse files Browse the repository at this point in the history
  • Loading branch information
cgm616 committed Oct 22, 2020
1 parent 6ab11c8 commit 05fe342
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 29 deletions.
4 changes: 0 additions & 4 deletions tests/ui/xor_used_as_pow.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// run-rustfix
#![warn(clippy::xor_used_as_pow)]
#![allow(clippy::identity_op)]

Expand All @@ -22,12 +21,9 @@ fn main() {
let _ = 2 ^ 0; // zero rhs

// These should fail
let _ = 2 ^ 3;
let _ = 10 ^ 4;
let _ = 2 ^ 32;
{
let x = 15;
let _ = 2 ^ x;
let _ = 10 ^ x;
}
}
27 changes: 4 additions & 23 deletions tests/ui/xor_used_as_pow.stderr
Original file line number Diff line number Diff line change
@@ -1,38 +1,19 @@
error: it appears you are trying to get a power of two, but `^` is not an exponentiation operator
--> $DIR/xor_used_as_pow.rs:25:13
|
LL | let _ = 2 ^ 3;
| ^^^^^ help: use a bitshift or constant instead: `1_u32 << 3`
|
= note: `-D clippy::xor-used-as-pow` implied by `-D warnings`

error: `^` is not an exponentiation operator but appears to have been used as one
--> $DIR/xor_used_as_pow.rs:26:13
--> $DIR/xor_used_as_pow.rs:24:13
|
LL | let _ = 10 ^ 4;
| ^^^^^^
|
= help: did you mean to use .pow()?

error: it appears you are trying to get a power of two, but `^` is not an exponentiation operator
--> $DIR/xor_used_as_pow.rs:27:13
|
LL | let _ = 2 ^ 32;
| ^^^^^^ help: use a bitshift or constant instead: `1_u64 << 32`

error: it appears you are trying to get a power of two, but `^` is not an exponentiation operator
--> $DIR/xor_used_as_pow.rs:30:17
|
LL | let _ = 2 ^ x;
| ^^^^^ help: use a bitshift or constant instead: `1 << x`
= note: `-D clippy::xor-used-as-pow` implied by `-D warnings`

error: `^` is not an exponentiation operator but appears to have been used as one
--> $DIR/xor_used_as_pow.rs:31:17
--> $DIR/xor_used_as_pow.rs:27:17
|
LL | let _ = 10 ^ x;
| ^^^^^^
|
= help: did you mean to use .pow()?

error: aborting due to 5 previous errors
error: aborting due to 2 previous errors

Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ fn main() {

// These should fail
let _ = 1_u32 << 3;
let _ = 10 ^ 4;
let _ = 1_u64 << 32;
{
let x = 15;
let _ = 1 << x;
let _ = 10 ^ x;
}
}
31 changes: 31 additions & 0 deletions tests/ui/xor_used_as_pow_fixable.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// run-rustfix
#![warn(clippy::xor_used_as_pow)]
#![allow(clippy::identity_op)]

// Should not be linted
#[allow(dead_code)]
enum E {
First = 1 ^ 8,
Second = 2 ^ 8,
Third = 3 ^ 8,
Tenth = 10 ^ 8,
}

fn main() {
// These should succeed:
let _ = 9 ^ 3; // lhs other than 2 or 10
let _ = 0x02 ^ 6; // lhs not decimal
let _ = 2 ^ 0x10; // rhs hexadecimal
let _ = 10 ^ 0b0101; // rhs binary
let _ = 2 ^ 0o1; // rhs octal
let _ = 10 ^ -18; // negative rhs
let _ = 2 ^ 0; // zero rhs

// These should fail
let _ = 2 ^ 3;
let _ = 2 ^ 32;
{
let x = 15;
let _ = 2 ^ x;
}
}
22 changes: 22 additions & 0 deletions tests/ui/xor_used_as_pow_fixable.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
error: it appears you are trying to get a power of two, but `^` is not an exponentiation operator
--> $DIR/xor_used_as_pow.rs:25:13
|
LL | let _ = 2 ^ 3;
| ^^^^^ help: use a bitshift or constant instead: `1_u32 << 3`
|
= note: `-D clippy::xor-used-as-pow` implied by `-D warnings`

error: it appears you are trying to get a power of two, but `^` is not an exponentiation operator
--> $DIR/xor_used_as_pow.rs:26:13
|
LL | let _ = 2 ^ 32;
| ^^^^^^ help: use a bitshift or constant instead: `1_u64 << 32`

error: it appears you are trying to get a power of two, but `^` is not an exponentiation operator
--> $DIR/xor_used_as_pow.rs:29:17
|
LL | let _ = 2 ^ x;
| ^^^^^ help: use a bitshift or constant instead: `1 << x`

error: aborting due to 3 previous errors

0 comments on commit 05fe342

Please sign in to comment.