]> git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/lint-exceeding-bitshifts.rs
New upstream version 1.26.0+dfsg1
[rustc.git] / src / test / compile-fail / lint-exceeding-bitshifts.rs
1 // Copyright 2014 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
11 #![deny(exceeding_bitshifts, const_err)]
12 #![allow(unused_variables)]
13 #![allow(dead_code)]
14
15 fn main() {
16 let n = 1u8 << 7;
17 let n = 1u8 << 8; //~ ERROR: attempt to shift left with overflow
18 let n = 1u16 << 15;
19 let n = 1u16 << 16; //~ ERROR: attempt to shift left with overflow
20 let n = 1u32 << 31;
21 let n = 1u32 << 32; //~ ERROR: attempt to shift left with overflow
22 let n = 1u64 << 63;
23 let n = 1u64 << 64; //~ ERROR: attempt to shift left with overflow
24 let n = 1i8 << 7;
25 let n = 1i8 << 8; //~ ERROR: attempt to shift left with overflow
26 let n = 1i16 << 15;
27 let n = 1i16 << 16; //~ ERROR: attempt to shift left with overflow
28 let n = 1i32 << 31;
29 let n = 1i32 << 32; //~ ERROR: attempt to shift left with overflow
30 let n = 1i64 << 63;
31 let n = 1i64 << 64; //~ ERROR: attempt to shift left with overflow
32
33 let n = 1u8 >> 7;
34 let n = 1u8 >> 8; //~ ERROR: attempt to shift right with overflow
35 let n = 1u16 >> 15;
36 let n = 1u16 >> 16; //~ ERROR: attempt to shift right with overflow
37 let n = 1u32 >> 31;
38 let n = 1u32 >> 32; //~ ERROR: attempt to shift right with overflow
39 let n = 1u64 >> 63;
40 let n = 1u64 >> 64; //~ ERROR: attempt to shift right with overflow
41 let n = 1i8 >> 7;
42 let n = 1i8 >> 8; //~ ERROR: attempt to shift right with overflow
43 let n = 1i16 >> 15;
44 let n = 1i16 >> 16; //~ ERROR: attempt to shift right with overflow
45 let n = 1i32 >> 31;
46 let n = 1i32 >> 32; //~ ERROR: attempt to shift right with overflow
47 let n = 1i64 >> 63;
48 let n = 1i64 >> 64; //~ ERROR: attempt to shift right with overflow
49
50 let n = 1u8;
51 let n = n << 7;
52 let n = n << 8; //~ ERROR: attempt to shift left with overflow
53
54 let n = 1u8 << -8; //~ ERROR: attempt to shift left with overflow
55
56 let n = 1i8<<(1isize+-1);
57 }