]>
git.proxmox.com Git - rustc.git/blob - src/test/ui/lint/lint-exceeding-bitshifts.rs
1 // revisions: noopt opt opt_with_overflow_checks
2 //[noopt]compile-flags: -C opt-level=0
3 //[opt]compile-flags: -O
4 //[opt_with_overflow_checks]compile-flags: -C overflow-checks=on -O
6 // ignore-pass (test emits codegen-time warnings and verifies that they are not errors)
7 // normalize-stderr-test "shift left by `(64|32)_usize`, which" -> "shift left by `%BITS%`, which"
10 #![warn(arithmetic_overflow, const_err)]
17 impl<T
: Foo
> Foo
for Vec
<T
> {
18 const N
: i32 = T
::N
<< 42; //~ WARN: arithmetic operation will overflow
22 let _
= x
<< 42; //~ WARN: arithmetic operation will overflow
27 let n
= 1u8 << 8; //~ WARN: arithmetic operation will overflow
29 let n
= 1u16 << 16; //~ WARN: arithmetic operation will overflow
31 let n
= 1u32 << 32; //~ WARN: arithmetic operation will overflow
33 let n
= 1u64 << 64; //~ WARN: arithmetic operation will overflow
35 let n
= 1i8 << 8; //~ WARN: arithmetic operation will overflow
37 let n
= 1i16 << 16; //~ WARN: arithmetic operation will overflow
39 let n
= 1i32 << 32; //~ WARN: arithmetic operation will overflow
41 let n
= 1i64 << 64; //~ WARN: arithmetic operation will overflow
44 let n
= 1u8 >> 8; //~ WARN: arithmetic operation will overflow
46 let n
= 1u16 >> 16; //~ WARN: arithmetic operation will overflow
48 let n
= 1u32 >> 32; //~ WARN: arithmetic operation will overflow
50 let n
= 1u64 >> 64; //~ WARN: arithmetic operation will overflow
52 let n
= 1i8 >> 8; //~ WARN: arithmetic operation will overflow
54 let n
= 1i16 >> 16; //~ WARN: arithmetic operation will overflow
56 let n
= 1i32 >> 32; //~ WARN: arithmetic operation will overflow
58 let n
= 1i64 >> 64; //~ WARN: arithmetic operation will overflow
62 let n
= n
<< 8; //~ WARN: arithmetic operation will overflow
64 let n
= 1u8 << -8; //~ WARN: arithmetic operation will overflow
66 let n
= 1i8<<(1isize
+-1);
69 let n
= 1u8 << (4+4); //~ WARN: arithmetic operation will overflow
70 let n
= 1i64 >> [63][0];
71 let n
= 1i64 >> [64][0]; //~ WARN: arithmetic operation will overflow
73 #[cfg(target_pointer_width = "32")]
74 const BITS
: usize = 32;
75 #[cfg(target_pointer_width = "64")]
76 const BITS
: usize = 64;
77 let n
= 1_isize
<< BITS
; //~ WARN: arithmetic operation will overflow
78 let n
= 1_usize
<< BITS
; //~ WARN: arithmetic operation will overflow