]>
Commit | Line | Data |
---|---|---|
c34b1796 AL |
1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT |
2 | // file at the top-level directory of this distribution and at | |
3 | // http://rust-lang.org/COPYRIGHT. | |
4 | // | |
5 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
6 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
7 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
8 | // option. This file may not be copied, modified, or distributed | |
9 | // except according to those terms. | |
10 | ||
54a0048b | 11 | #![feature(rustc_attrs)] |
c34b1796 AL |
12 | #![deny(warnings)] |
13 | ||
14 | use std::env; | |
15 | use std::thread; | |
16 | ||
17 | fn main() { | |
18 | let should_fail = env::args().nth(1) == Some("bad".to_string()); | |
19 | ||
20 | assert_eq!(thread::spawn(debug_assert_eq).join().is_err(), should_fail); | |
21 | assert_eq!(thread::spawn(debug_assert).join().is_err(), should_fail); | |
22 | assert_eq!(thread::spawn(overflow).join().is_err(), should_fail); | |
23 | } | |
24 | ||
25 | fn debug_assert_eq() { | |
26 | let mut hit1 = false; | |
27 | let mut hit2 = false; | |
28 | debug_assert_eq!({ hit1 = true; 1 }, { hit2 = true; 2 }); | |
29 | assert!(!hit1); | |
30 | assert!(!hit2); | |
31 | } | |
32 | ||
33 | fn debug_assert() { | |
34 | let mut hit = false; | |
35 | debug_assert!({ hit = true; false }); | |
36 | assert!(!hit); | |
37 | } | |
38 | ||
39 | fn overflow() { | |
54a0048b | 40 | #[rustc_no_mir] // FIXME #29769 MIR overflow checking is TBD. |
c34b1796 AL |
41 | fn add(a: u8, b: u8) -> u8 { a + b } |
42 | ||
43 | add(200u8, 200u8); | |
44 | } |