Skip to content

Commit 05fe342

Browse files
committed
Separate tests into fixable and unfixable
1 parent 6ab11c8 commit 05fe342

5 files changed

+57
-29
lines changed

tests/ui/xor_used_as_pow.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// run-rustfix
21
#![warn(clippy::xor_used_as_pow)]
32
#![allow(clippy::identity_op)]
43

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

2423
// These should fail
25-
let _ = 2 ^ 3;
2624
let _ = 10 ^ 4;
27-
let _ = 2 ^ 32;
2825
{
2926
let x = 15;
30-
let _ = 2 ^ x;
3127
let _ = 10 ^ x;
3228
}
3329
}

tests/ui/xor_used_as_pow.stderr

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,19 @@
1-
error: it appears you are trying to get a power of two, but `^` is not an exponentiation operator
2-
--> $DIR/xor_used_as_pow.rs:25:13
3-
|
4-
LL | let _ = 2 ^ 3;
5-
| ^^^^^ help: use a bitshift or constant instead: `1_u32 << 3`
6-
|
7-
= note: `-D clippy::xor-used-as-pow` implied by `-D warnings`
8-
91
error: `^` is not an exponentiation operator but appears to have been used as one
10-
--> $DIR/xor_used_as_pow.rs:26:13
2+
--> $DIR/xor_used_as_pow.rs:24:13
113
|
124
LL | let _ = 10 ^ 4;
135
| ^^^^^^
146
|
157
= help: did you mean to use .pow()?
16-
17-
error: it appears you are trying to get a power of two, but `^` is not an exponentiation operator
18-
--> $DIR/xor_used_as_pow.rs:27:13
19-
|
20-
LL | let _ = 2 ^ 32;
21-
| ^^^^^^ help: use a bitshift or constant instead: `1_u64 << 32`
22-
23-
error: it appears you are trying to get a power of two, but `^` is not an exponentiation operator
24-
--> $DIR/xor_used_as_pow.rs:30:17
25-
|
26-
LL | let _ = 2 ^ x;
27-
| ^^^^^ help: use a bitshift or constant instead: `1 << x`
8+
= note: `-D clippy::xor-used-as-pow` implied by `-D warnings`
289

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

37-
error: aborting due to 5 previous errors
18+
error: aborting due to 2 previous errors
3819

tests/ui/xor_used_as_pow.fixed renamed to tests/ui/xor_used_as_pow_fixable.fixed

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@ fn main() {
2323

2424
// These should fail
2525
let _ = 1_u32 << 3;
26-
let _ = 10 ^ 4;
2726
let _ = 1_u64 << 32;
2827
{
2928
let x = 15;
3029
let _ = 1 << x;
31-
let _ = 10 ^ x;
3230
}
3331
}

tests/ui/xor_used_as_pow_fixable.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// run-rustfix
2+
#![warn(clippy::xor_used_as_pow)]
3+
#![allow(clippy::identity_op)]
4+
5+
// Should not be linted
6+
#[allow(dead_code)]
7+
enum E {
8+
First = 1 ^ 8,
9+
Second = 2 ^ 8,
10+
Third = 3 ^ 8,
11+
Tenth = 10 ^ 8,
12+
}
13+
14+
fn main() {
15+
// These should succeed:
16+
let _ = 9 ^ 3; // lhs other than 2 or 10
17+
let _ = 0x02 ^ 6; // lhs not decimal
18+
let _ = 2 ^ 0x10; // rhs hexadecimal
19+
let _ = 10 ^ 0b0101; // rhs binary
20+
let _ = 2 ^ 0o1; // rhs octal
21+
let _ = 10 ^ -18; // negative rhs
22+
let _ = 2 ^ 0; // zero rhs
23+
24+
// These should fail
25+
let _ = 2 ^ 3;
26+
let _ = 2 ^ 32;
27+
{
28+
let x = 15;
29+
let _ = 2 ^ x;
30+
}
31+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error: it appears you are trying to get a power of two, but `^` is not an exponentiation operator
2+
--> $DIR/xor_used_as_pow.rs:25:13
3+
|
4+
LL | let _ = 2 ^ 3;
5+
| ^^^^^ help: use a bitshift or constant instead: `1_u32 << 3`
6+
|
7+
= note: `-D clippy::xor-used-as-pow` implied by `-D warnings`
8+
9+
error: it appears you are trying to get a power of two, but `^` is not an exponentiation operator
10+
--> $DIR/xor_used_as_pow.rs:26:13
11+
|
12+
LL | let _ = 2 ^ 32;
13+
| ^^^^^^ help: use a bitshift or constant instead: `1_u64 << 32`
14+
15+
error: it appears you are trying to get a power of two, but `^` is not an exponentiation operator
16+
--> $DIR/xor_used_as_pow.rs:29:17
17+
|
18+
LL | let _ = 2 ^ x;
19+
| ^^^^^ help: use a bitshift or constant instead: `1 << x`
20+
21+
error: aborting due to 3 previous errors
22+

0 commit comments

Comments
 (0)