]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/pass/ints.rs
Auto merge of #104915 - weihanglo:update-cargo, r=ehuss
[rust.git] / src / tools / miri / tests / pass / ints.rs
1 fn ret() -> i64 {
2     1
3 }
4
5 fn neg() -> i64 {
6     -1
7 }
8
9 fn add() -> i64 {
10     1 + 2
11 }
12
13 fn indirect_add() -> i64 {
14     let x = 1;
15     let y = 2;
16     x + y
17 }
18
19 fn arith() -> i32 {
20     3 * 3 + 4 * 4
21 }
22
23 fn match_int() -> i16 {
24     let n = 2;
25     match n {
26         0 => 0,
27         1 => 10,
28         2 => 20,
29         3 => 30,
30         _ => 100,
31     }
32 }
33
34 fn match_int_range() -> i64 {
35     let n = 42;
36     match n {
37         0..=9 => 0,
38         10..=19 => 1,
39         20..=29 => 2,
40         30..=39 => 3,
41         40..=42 => 4,
42         _ => 5,
43     }
44 }
45
46 fn main() {
47     assert_eq!(ret(), 1);
48     assert_eq!(neg(), -1);
49     assert_eq!(add(), 3);
50     assert_eq!(indirect_add(), 3);
51     assert_eq!(arith(), 5 * 5);
52     assert_eq!(match_int(), 20);
53     assert_eq!(match_int_range(), 4);
54     assert_eq!(i64::MIN.overflowing_mul(-1), (i64::MIN, true));
55     assert_eq!(i32::MIN.overflowing_mul(-1), (i32::MIN, true));
56     assert_eq!(i16::MIN.overflowing_mul(-1), (i16::MIN, true));
57     assert_eq!(i8::MIN.overflowing_mul(-1), (i8::MIN, true));
58 }