]> git.lizzy.rs Git - rust.git/blob - tests/ui/arithmetic.rs
Auto merge of #3603 - xfix:random-state-lint, r=phansch
[rust.git] / tests / ui / arithmetic.rs
1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10 #![warn(clippy::integer_arithmetic, clippy::float_arithmetic)]
11 #![allow(
12     unused,
13     clippy::shadow_reuse,
14     clippy::shadow_unrelated,
15     clippy::no_effect,
16     clippy::unnecessary_operation
17 )]
18
19 #[rustfmt::skip]
20 fn main() {
21     let i = 1i32;
22     1 + i;
23     i * 2;
24     1 %
25     i / 2; // no error, this is part of the expression in the preceding line
26     i - 2 + 2 - i;
27     -i;
28
29     i & 1; // no wrapping
30     i | 1;
31     i ^ 1;
32     i >> 1;
33     i << 1;
34
35     let f = 1.0f32;
36
37     f * 2.0;
38
39     1.0 + f;
40     f * 2.0;
41     f / 2.0;
42     f - 2.0 * 4.2;
43     -f;
44
45     // No errors for the following items because they are constant expressions
46     enum Foo {
47         Bar = -2,
48     }
49     struct Baz([i32; 1 + 1]);
50     union Qux {
51         field: [i32; 1 + 1],
52     }
53     type Alias = [i32; 1 + 1];
54
55     const FOO: i32 = -2;
56     static BAR: i32 = -2;
57
58     let _: [i32; 1 + 1] = [0, 0];
59
60     let _: [i32; 1 + 1] = {
61         let a: [i32; 1 + 1] = [0, 0];
62         a
63     };
64
65     trait Trait {
66         const ASSOC: i32 = 1 + 1;
67     }
68
69     impl Trait for Foo {
70         const ASSOC: i32 = {
71             let _: [i32; 1 + 1];
72             fn foo() {}
73             1 + 1
74         };
75     }
76 }