-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
63 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +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:24: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:25:13 | ||
--> $DIR/xor_used_as_pow.rs:24:13 | ||
| | ||
LL | let _ = 10 ^ 4; | ||
| ^^^^^^ | ||
| | ||
= note: `-D clippy::xor-used-as-pow` implied by `-D warnings` | ||
= 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: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:27:13 | ||
| | ||
LL | let _ = 2 ^ 0; | ||
| ^^^^^ help: use a bitshift or constant instead: `1` | ||
|
||
error: `^` is not an exponentiation operator but appears to have been used as one | ||
--> $DIR/xor_used_as_pow.rs:28:13 | ||
| | ||
LL | let _ = 10 ^ 0; | ||
| ^^^^^^ | ||
| | ||
= 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:31:17 | ||
| | ||
LL | let _ = 2 ^ x; | ||
| ^^^^^ help: use a bitshift or constant instead: `1 << x` | ||
|
||
error: `^` is not an exponentiation operator but appears to have been used as one | ||
--> $DIR/xor_used_as_pow.rs:32:17 | ||
--> $DIR/xor_used_as_pow.rs:27:17 | ||
| | ||
LL | let _ = 10 ^ x; | ||
| ^^^^^^ | ||
| | ||
= help: did you mean to use .pow()? | ||
|
||
error: aborting due to 7 previous errors | ||
error: aborting due to 2 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_fixable.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_fixable.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_fixable.rs:29:17 | ||
| | ||
LL | let _ = 2 ^ x; | ||
| ^^^^^ help: use a bitshift or constant instead: `1 << x` | ||
|
||
error: aborting due to 3 previous errors | ||
|