]> git.lizzy.rs Git - rust.git/blob - tests/ui/arithmetic.rs
Auto merge of #3527 - phansch:update_readme2, r=matthiaskrgr
[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 #![warn(clippy::integer_arithmetic, clippy::float_arithmetic)]
12 #![allow(unused, clippy::shadow_reuse, clippy::shadow_unrelated, clippy::no_effect, clippy::unnecessary_operation)]
13
14 #[rustfmt::skip]
15 fn main() {
16     let i = 1i32;
17     1 + i;
18     i * 2;
19     1 %
20     i / 2; // no error, this is part of the expression in the preceding line
21     i - 2 + 2 - i;
22     -i;
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 }