]> git.lizzy.rs Git - rust.git/blob - tests/ui/identity_op.rs
return_self_not_must_use document `#[must_use]` on the type
[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 #[allow(
15     clippy::eq_op,
16     clippy::no_effect,
17     clippy::unnecessary_operation,
18     clippy::op_ref,
19     clippy::double_parens
20 )]
21 #[warn(clippy::identity_op)]
22 #[rustfmt::skip]
23 fn main() {
24     let x = 0;
25
26     x + 0;
27     x + (1 - 1);
28     x + 1;
29     0 + x;
30     1 + x;
31     x - ZERO; //no error, as we skip lookups (for now)
32     x | (0);
33     ((ZERO)) | x; //no error, as we skip lookups (for now)
34
35     x * 1;
36     1 * x;
37     x / ONE; //no error, as we skip lookups (for now)
38
39     x / 2; //no false positive
40
41     x & NEG_ONE; //no error, as we skip lookups (for now)
42     -1 & x;
43
44     let u: u8 = 0;
45     u & 255;
46
47     1 << 0; // no error, this case is allowed, see issue 3430
48     42 << 0;
49     1 >> 0;
50     42 >> 0;
51     &x >> 0;
52     x >> &0;
53
54     let mut a = A("".into());
55     let b = a << 0; // no error: non-integer
56 }