]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/tests/ui/identity_op.rs
Update upstream source from tag 'upstream/1.52.1+dfsg1'
[rustc.git] / src / tools / clippy / tests / ui / identity_op.rs
CommitLineData
f20569fa
XL
1const ONE: i64 = 1;
2const NEG_ONE: i64 = -1;
3const ZERO: i64 = 0;
4
5#[allow(
6 clippy::eq_op,
7 clippy::no_effect,
8 clippy::unnecessary_operation,
9 clippy::double_parens
10)]
11#[warn(clippy::identity_op)]
12#[rustfmt::skip]
13fn main() {
14 let x = 0;
15
16 x + 0;
17 x + (1 - 1);
18 x + 1;
19 0 + x;
20 1 + x;
21 x - ZERO; //no error, as we skip lookups (for now)
22 x | (0);
23 ((ZERO)) | x; //no error, as we skip lookups (for now)
24
25 x * 1;
26 1 * x;
27 x / ONE; //no error, as we skip lookups (for now)
28
29 x / 2; //no false positive
30
31 x & NEG_ONE; //no error, as we skip lookups (for now)
32 -1 & x;
33
34 let u: u8 = 0;
35 u & 255;
36
37 1 << 0; // no error, this case is allowed, see issue 3430
38 42 << 0;
39 1 >> 0;
40 42 >> 0;
41}