]> git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/lint-exceeding-bitshifts.rs
5867bc2f09deb273967b0c986178d108acfb0bf2
[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 #![feature(negate_unsigned)]
12 #![deny(exceeding_bitshifts)]
13 #![allow(unused_variables)]
14 #![allow(dead_code)]
15 #![feature(num_bits_bytes, negate_unsigned)]
16
17 fn main() {
18 let n = 1u8 << 7;
19 let n = 1u8 << 8; //~ ERROR: bitshift exceeds the type's number of bits
20 let n = 1u16 << 15;
21 let n = 1u16 << 16; //~ ERROR: bitshift exceeds the type's number of bits
22 let n = 1u32 << 31;
23 let n = 1u32 << 32; //~ ERROR: bitshift exceeds the type's number of bits
24 let n = 1u64 << 63;
25 let n = 1u64 << 64; //~ ERROR: bitshift exceeds the type's number of bits
26 let n = 1i8 << 7;
27 let n = 1i8 << 8; //~ ERROR: bitshift exceeds the type's number of bits
28 let n = 1i16 << 15;
29 let n = 1i16 << 16; //~ ERROR: bitshift exceeds the type's number of bits
30 let n = 1i32 << 31;
31 let n = 1i32 << 32; //~ ERROR: bitshift exceeds the type's number of bits
32 let n = 1i64 << 63;
33 let n = 1i64 << 64; //~ ERROR: bitshift exceeds the type's number of bits
34
35 let n = 1u8 >> 7;
36 let n = 1u8 >> 8; //~ ERROR: bitshift exceeds the type's number of bits
37 let n = 1u16 >> 15;
38 let n = 1u16 >> 16; //~ ERROR: bitshift exceeds the type's number of bits
39 let n = 1u32 >> 31;
40 let n = 1u32 >> 32; //~ ERROR: bitshift exceeds the type's number of bits
41 let n = 1u64 >> 63;
42 let n = 1u64 >> 64; //~ ERROR: bitshift exceeds the type's number of bits
43 let n = 1i8 >> 7;
44 let n = 1i8 >> 8; //~ ERROR: bitshift exceeds the type's number of bits
45 let n = 1i16 >> 15;
46 let n = 1i16 >> 16; //~ ERROR: bitshift exceeds the type's number of bits
47 let n = 1i32 >> 31;
48 let n = 1i32 >> 32; //~ ERROR: bitshift exceeds the type's number of bits
49 let n = 1i64 >> 63;
50 let n = 1i64 >> 64; //~ ERROR: bitshift exceeds the type's number of bits
51
52 let n = 1u8;
53 let n = n << 7;
54 let n = n << 8; //~ ERROR: bitshift exceeds the type's number of bits
55
56 let n = 1u8 << -8; //~ ERROR: bitshift exceeds the type's number of bits
57
58 let n = 1u8 << (4+3);
59 let n = 1u8 << (4+4); //~ ERROR: bitshift exceeds the type's number of bits
60
61 let n = 1_isize << std::isize::BITS; //~ ERROR: bitshift exceeds the type's number of bits
62 let n = 1_usize << std::usize::BITS; //~ ERROR: bitshift exceeds the type's number of bits
63 }