]> git.lizzy.rs Git - rust.git/blob - tests/ui/identity_op.rs
Auto merge of #3603 - xfix:random-state-lint, r=phansch
[rust.git] / tests / ui / identity_op.rs
1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10 const ONE: i64 = 1;
11 const NEG_ONE: i64 = -1;
12 const ZERO: i64 = 0;
13
14 #[allow(
15     clippy::eq_op,
16     clippy::no_effect,
17     clippy::unnecessary_operation,
18     clippy::double_parens
19 )]
20 #[warn(clippy::identity_op)]
21 #[rustfmt::skip]
22 fn main() {
23     let x = 0;
24
25     x + 0;
26     x + (1 - 1);
27     x + 1;
28     0 + x;
29     1 + x;
30     x - ZERO; //no error, as we skip lookups (for now)
31     x | (0);
32     ((ZERO)) | x; //no error, as we skip lookups (for now)
33
34     x * 1;
35     1 * x;
36     x / ONE; //no error, as we skip lookups (for now)
37
38     x / 2; //no false positive
39
40     x & NEG_ONE; //no error, as we skip lookups (for now)
41     -1 & x;
42
43     let u: u8 = 0;
44     u & 255;
45 }