Skip to content

Commit 27488fe

Browse files
committed
Add expected output to tests
1 parent 08611b0 commit 27488fe

File tree

2 files changed

+71
-11
lines changed

2 files changed

+71
-11
lines changed

tests/ui/xor_used_as_pow.fixed

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// run-rustfix
2+
#![warn(clippy::xor_used_as_pow)]
3+
4+
// Should not be linted
5+
enum E {
6+
First = 1 ^ 8,
7+
Second = 2 ^ 8,
8+
Third = 3 ^ 8,
9+
Tenth = 10 ^ 8,
10+
}
11+
12+
fn main() {
13+
// These should succeed:
14+
let _ = 9 ^ 3; // lhs other than 2 or 10
15+
let _ = 0x02 ^ 6; // lhs not decimal
16+
let _ = 2 ^ 0x10; // rhs hexadecimal
17+
let _ = 10 ^ 0b0101; // rhs binary
18+
let _ = 2 ^ 0o1; // rhs octal
19+
let _ = 10 ^ -18; // negative rhs
20+
21+
// These should fail
22+
let _ = 1_u32 << 3;
23+
let _ = 10 ^ 4;
24+
let _ = 1_u64 << 32;
25+
let _ = 1;
26+
let _ = 10 ^ 0;
27+
{
28+
let x = 15;
29+
let _ = 2 ^ x;
30+
let _ = 10 ^ x;
31+
}
32+
}

tests/ui/xor_used_as_pow.stderr

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,52 @@
1-
error: it appears you are trying to get the maximum value of an integer, but `^` is not an exponentiation operator
2-
--> $DIR/xor_used_as_pow.rs:12:20
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:22:13
33
|
4-
LL | println!("{}", 2 ^ 16);
5-
| ^^^^^^ help: try: `std::u16::MAX`
4+
LL | let _ = 2 ^ 3;
5+
| ^^^^^ help: use a bitshift instead: `1_u32 << 3`
66
|
77
= note: `-D clippy::xor-used-as-pow` implied by `-D warnings`
88

9+
error: `^` is not an exponentiation operator but appears to have been used as one
10+
--> $DIR/xor_used_as_pow.rs:23:13
11+
|
12+
LL | let _ = 10 ^ 4;
13+
| ^^^^^^
14+
|
15+
= 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:24:13
19+
|
20+
LL | let _ = 2 ^ 32;
21+
| ^^^^^^ help: use a bitshift instead: `1_u64 << 32`
22+
23+
error: the operation is ineffective. Consider reducing it to `2`
24+
--> $DIR/xor_used_as_pow.rs:25:13
25+
|
26+
LL | let _ = 2 ^ 0;
27+
| ^^^^^
28+
|
29+
= note: `-D clippy::identity-op` implied by `-D warnings`
30+
931
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:13:20
32+
--> $DIR/xor_used_as_pow.rs:25:13
33+
|
34+
LL | let _ = 2 ^ 0;
35+
| ^^^^^ help: try: `1`
36+
37+
error: the operation is ineffective. Consider reducing it to `10`
38+
--> $DIR/xor_used_as_pow.rs:26:13
1139
|
12-
LL | println!("{}", 2 ^ 7);
13-
| ^^^^^ help: use a bitshift instead: `1 << 7`
40+
LL | let _ = 10 ^ 0;
41+
| ^^^^^^
1442

1543
error: `^` is not an exponentiation operator but appears to have been used as one
16-
--> $DIR/xor_used_as_pow.rs:14:20
44+
--> $DIR/xor_used_as_pow.rs:26:13
1745
|
18-
LL | println!("{}", 9 ^ 3);
19-
| ^^^^^
46+
LL | let _ = 10 ^ 0;
47+
| ^^^^^^
2048
|
2149
= help: did you mean to use .pow()?
2250

23-
error: aborting due to 3 previous errors
51+
error: aborting due to 7 previous errors
2452

0 commit comments

Comments
 (0)