]> git.lizzy.rs Git - rust.git/blob - tests/ui/identity_op.rs
Auto merge of #8374 - Alexendoo:bless-revisions, r=camsteffen
[rust.git] / tests / ui / identity_op.rs
1 const ONE: i64 = 1;
2 const NEG_ONE: i64 = -1;
3 const ZERO: i64 = 0;
4
5 struct A(String);
6
7 impl std::ops::Shl<i32> for A {
8     type Output = A;
9     fn shl(mut self, other: i32) -> Self {
10         self.0.push_str(&format!("{}", other));
11         self
12     }
13 }
14
15 struct Length(u8);
16 struct Meter;
17
18 impl core::ops::Mul<Meter> for u8 {
19     type Output = Length;
20     fn mul(self, _: Meter) -> Length {
21         Length(self)
22     }
23 }
24
25 #[allow(
26     clippy::eq_op,
27     clippy::no_effect,
28     clippy::unnecessary_operation,
29     clippy::op_ref,
30     clippy::double_parens
31 )]
32 #[warn(clippy::identity_op)]
33 #[rustfmt::skip]
34 fn main() {
35     let x = 0;
36
37     x + 0;
38     x + (1 - 1);
39     x + 1;
40     0 + x;
41     1 + x;
42     x - ZERO; //no error, as we skip lookups (for now)
43     x | (0);
44     ((ZERO)) | x; //no error, as we skip lookups (for now)
45
46     x * 1;
47     1 * x;
48     x / ONE; //no error, as we skip lookups (for now)
49
50     x / 2; //no false positive
51
52     x & NEG_ONE; //no error, as we skip lookups (for now)
53     -1 & x;
54
55     let u: u8 = 0;
56     u & 255;
57
58     1 << 0; // no error, this case is allowed, see issue 3430
59     42 << 0;
60     1 >> 0;
61     42 >> 0;
62     &x >> 0;
63     x >> &0;
64
65     let mut a = A("".into());
66     let b = a << 0; // no error: non-integer
67
68     1 * Meter; // no error: non-integer
69 }