]> git.lizzy.rs Git - rust.git/blob - tests/ui/arithmetic.rs
Remove negative integer literal checks.
[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; // no error, overflows are checked by `overflowing_literals`
19
20     i & 1; // no wrapping
21     i | 1;
22     i ^ 1;
23     i >> 1;
24     i << 1;
25
26     let f = 1.0f32;
27
28     f * 2.0;
29
30     1.0 + f;
31     f * 2.0;
32     f / 2.0;
33     f - 2.0 * 4.2;
34     -f;
35
36     // No errors for the following items because they are constant expressions
37     enum Foo {
38         Bar = -2,
39     }
40     struct Baz([i32; 1 + 1]);
41     union Qux {
42         field: [i32; 1 + 1],
43     }
44     type Alias = [i32; 1 + 1];
45
46     const FOO: i32 = -2;
47     static BAR: i32 = -2;
48
49     let _: [i32; 1 + 1] = [0, 0];
50
51     let _: [i32; 1 + 1] = {
52         let a: [i32; 1 + 1] = [0, 0];
53         a
54     };
55
56     trait Trait {
57         const ASSOC: i32 = 1 + 1;
58     }
59
60     impl Trait for Foo {
61         const ASSOC: i32 = {
62             let _: [i32; 1 + 1];
63             fn foo() {}
64             1 + 1
65         };
66     }
67 }