]> git.lizzy.rs Git - rust.git/blob - tests/ui/arithmetic.rs
Auto merge of #4314 - chansuke:add-negation-to-is_empty, r=flip1995
[rust.git] / tests / ui / arithmetic.rs
1 #![warn(clippy::integer_arithmetic, clippy::float_arithmetic)]
2 #![allow(
3     unused,
4     clippy::shadow_reuse,
5     clippy::shadow_unrelated,
6     clippy::no_effect,
7     clippy::unnecessary_operation
8 )]
9
10 #[rustfmt::skip]
11 fn main() {
12     let i = 1i32;
13     1 + i;
14     i * 2;
15     1 %
16     i / 2; // no error, this is part of the expression in the preceding line
17     i - 2 + 2 - i;
18     -i;
19
20     // no error, overflows are checked by `overflowing_literals`
21     -1;
22     -(-1);
23
24     i & 1; // no wrapping
25     i | 1;
26     i ^ 1;
27     i >> 1;
28     i << 1;
29
30     let f = 1.0f32;
31
32     f * 2.0;
33
34     1.0 + f;
35     f * 2.0;
36     f / 2.0;
37     f - 2.0 * 4.2;
38     -f;
39
40     // No errors for the following items because they are constant expressions
41     enum Foo {
42         Bar = -2,
43     }
44     struct Baz([i32; 1 + 1]);
45     union Qux {
46         field: [i32; 1 + 1],
47     }
48     type Alias = [i32; 1 + 1];
49
50     const FOO: i32 = -2;
51     static BAR: i32 = -2;
52
53     let _: [i32; 1 + 1] = [0, 0];
54
55     let _: [i32; 1 + 1] = {
56         let a: [i32; 1 + 1] = [0, 0];
57         a
58     };
59
60     trait Trait {
61         const ASSOC: i32 = 1 + 1;
62     }
63
64     impl Trait for Foo {
65         const ASSOC: i32 = {
66             let _: [i32; 1 + 1];
67             fn foo() {}
68             1 + 1
69         };
70     }
71 }