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