File tree 5 files changed +57
-29
lines changed 5 files changed +57
-29
lines changed Original file line number Diff line number Diff line change 1
- // run-rustfix
2
1
#![ warn( clippy:: xor_used_as_pow) ]
3
2
#![ allow( clippy:: identity_op) ]
4
3
@@ -22,12 +21,9 @@ fn main() {
22
21
let _ = 2 ^ 0 ; // zero rhs
23
22
24
23
// These should fail
25
- let _ = 2 ^ 3 ;
26
24
let _ = 10 ^ 4 ;
27
- let _ = 2 ^ 32 ;
28
25
{
29
26
let x = 15 ;
30
- let _ = 2 ^ x;
31
27
let _ = 10 ^ x;
32
28
}
33
29
}
Original file line number Diff line number Diff line change 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
1
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
11
3
|
12
4
LL | let _ = 10 ^ 4;
13
5
| ^^^^^^
14
6
|
15
7
= 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`
28
9
29
10
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
31
12
|
32
13
LL | let _ = 10 ^ x;
33
14
| ^^^^^^
34
15
|
35
16
= help: did you mean to use .pow()?
36
17
37
- error: aborting due to 5 previous errors
18
+ error: aborting due to 2 previous errors
38
19
Original file line number Diff line number Diff line change @@ -23,11 +23,9 @@ fn main() {
23
23
24
24
// These should fail
25
25
let _ = 1_u32 << 3;
26
- let _ = 10 ^ 4;
27
26
let _ = 1_u64 << 32;
28
27
{
29
28
let x = 15;
30
29
let _ = 1 << x;
31
- let _ = 10 ^ x;
32
30
}
33
31
}
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+
You can’t perform that action at this time.
0 commit comments