]> git.lizzy.rs Git - rust.git/blob - tests/ui/identity_op.rs
Merge pull request #3269 from rust-lang-nursery/relicense
[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
11 #![feature(tool_lints)]
12
13
14 const ONE : i64 = 1;
15 const NEG_ONE : i64 = -1;
16 const ZERO : i64 = 0;
17
18 #[allow(clippy::eq_op, clippy::no_effect, clippy::unnecessary_operation, clippy::double_parens)]
19 #[warn(clippy::identity_op)]
20 fn main() {
21     let x = 0;
22
23     x + 0;
24     x + (1 - 1);
25     x + 1;
26     0 + x;
27     1 + x;
28     x - ZERO;     //no error, as we skip lookups (for now)
29     x | (0);
30     ((ZERO)) | x; //no error, as we skip lookups (for now)
31
32     x * 1;
33     1 * x;
34     x / ONE;      //no error, as we skip lookups (for now)
35
36     x / 2;        //no false positive
37
38     x & NEG_ONE;  //no error, as we skip lookups (for now)
39     -1 & x;
40
41     let u : u8 = 0;
42     u & 255;
43 }