]> git.lizzy.rs Git - rust.git/blob - src/test/run-fail/overflowing-rsh-4.rs
Use better bound names in `-Zverbose` mode
[rust.git] / src / test / run-fail / overflowing-rsh-4.rs
1 // error-pattern:thread 'main' panicked at 'attempt to shift right with overflow'
2 // compile-flags: -C debug-assertions
3
4 // This function is checking that our (type-based) automatic
5 // truncation does not sidestep the overflow checking.
6
7 #![warn(exceeding_bitshifts)]
8 #![warn(const_err)]
9
10 fn main() {
11     // this signals overflow when checking is on
12     let x = 2_i8 >> 17;
13
14     // ... but when checking is off, the fallback will truncate the
15     // input to its lower three bits (= 1). Note that this is *not*
16     // the behavior of the x86 processor for 8- and 16-bit types,
17     // but it is necessary to avoid undefined behavior from LLVM.
18     //
19     // We check that here, by ensuring the result is not zero; if
20     // overflow checking is turned off, then this assertion will pass
21     // (and the compiletest driver will report that the test did not
22     // produce the error expected above).
23     assert_eq!(x, 1_i8);
24 }