fork/rust

git clone https://git.julia.blue/fork/rust

borsAuto merge of #103046 - JanBeh:PR_clarify_cmp_terminology, r=workingjubilee3bcad65fbf6

master
2.3 KiB122 linesraw
1#![warn(clippy::identity_op)]
2#![allow(unused)]
3#![allow(
4    clippy::eq_op,
5    clippy::no_effect,
6    clippy::unnecessary_operation,
7    clippy::op_ref,
8    clippy::double_parens,
9    clippy::uninlined_format_args
10)]
11
12use std::fmt::Write as _;
13
14const ONE: i64 = 1;
15const NEG_ONE: i64 = -1;
16const ZERO: i64 = 0;
17
18struct A(String);
19
20impl std::ops::Shl<i32> for A {
21    type Output = A;
22    fn shl(mut self, other: i32) -> Self {
23        let _ = write!(self.0, "{}", other);
24        self
25    }
26}
27
28struct Length(u8);
29struct Meter;
30
31impl core::ops::Mul<Meter> for u8 {
32    type Output = Length;
33    fn mul(self, _: Meter) -> Length {
34        Length(self)
35    }
36}
37
38#[rustfmt::skip]
39fn main() {
40    let x = 0;
41
42    x;
43    x;
44    x + 1;
45    x;
46    1 + x;
47    x - ZERO; //no error, as we skip lookups (for now)
48    x;
49    ((ZERO)) | x; //no error, as we skip lookups (for now)
50
51    x;
52    x;
53    x / ONE; //no error, as we skip lookups (for now)
54
55    x / 2; //no false positive
56
57    x & NEG_ONE; //no error, as we skip lookups (for now)
58    x;
59
60    let u: u8 = 0;
61    u;
62
63    1 << 0; // no error, this case is allowed, see issue 3430
64    42;
65    1;
66    42;
67    x;
68    x;
69
70    let mut a = A(String::new());
71    let b = a << 0; // no error: non-integer
72
73    1 * Meter; // no error: non-integer
74
75    2;
76    -2;
77    2 + x;
78    -2 + x;
79    x + 1;
80    (x + 1) % 3; // no error
81    4 % 3; // no error
82    4 % -3; // no error
83
84    // See #8724
85    let a = 0;
86    let b = true;
87    (if b { 1 } else { 2 });
88    (if b { 1 } else { 2 }) + if b { 3 } else { 4 };
89    (match a { 0 => 10, _ => 20 });
90    (match a { 0 => 10, _ => 20 }) + match a { 0 => 30, _ => 40 };
91    (if b { 1 } else { 2 }) + match a { 0 => 30, _ => 40 };
92    (match a { 0 => 10, _ => 20 }) + if b { 3 } else { 4 };
93    (if b { 1 } else { 2 });
94
95    ({ a }) + 3;
96    ({ a } * 2);
97    (loop { let mut c = 0; if c == 10 { break c; } c += 1; }) + { a * 2 };
98
99    fn f(_: i32) {
100        todo!();
101    }
102    f(a + { 8 * 5 });
103    f(if b { 1 } else { 2 } + 3);
104    const _: i32 = { 2 * 4 } + 3;
105    const _: i32 = { 1 + 2 * 3 } + 3;
106
107    a as usize;
108    let _ = a as usize;
109    ({ a } as usize);
110
111    2 * { a };
112    (({ a } + 4));
113    1;
114
115    // Issue #9904
116    let x = 0i32;
117    let _: i32 = x;
118}
119
120pub fn decide(a: bool, b: bool) -> u32 {
121    (if a { 1 } else { 2 }) + if b { 3 } else { 5 }
122}