]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/lint-exceeding-bitshifts.rs
Nuke the entire ctfe from orbit, it's the only way to be sure
[rust.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)]
12 #![allow(unused_variables)]
13 #![allow(dead_code)]
14 #![feature(const_indexing)]
15
16 fn main() {
17       let n = 1u8 << 7;
18       let n = 1u8 << 8;   //~ ERROR: bitshift exceeds the type's number of bits
19       let n = 1u16 << 15;
20       let n = 1u16 << 16; //~ ERROR: bitshift exceeds the type's number of bits
21       let n = 1u32 << 31;
22       let n = 1u32 << 32; //~ ERROR: bitshift exceeds the type's number of bits
23       let n = 1u64 << 63;
24       let n = 1u64 << 64; //~ ERROR: bitshift exceeds the type's number of bits
25       let n = 1i8 << 7;
26       let n = 1i8 << 8;   //~ ERROR: bitshift exceeds the type's number of bits
27       let n = 1i16 << 15;
28       let n = 1i16 << 16; //~ ERROR: bitshift exceeds the type's number of bits
29       let n = 1i32 << 31;
30       let n = 1i32 << 32; //~ ERROR: bitshift exceeds the type's number of bits
31       let n = 1i64 << 63;
32       let n = 1i64 << 64; //~ ERROR: bitshift exceeds the type's number of bits
33
34       let n = 1u8 >> 7;
35       let n = 1u8 >> 8;   //~ ERROR: bitshift exceeds the type's number of bits
36       let n = 1u16 >> 15;
37       let n = 1u16 >> 16; //~ ERROR: bitshift exceeds the type's number of bits
38       let n = 1u32 >> 31;
39       let n = 1u32 >> 32; //~ ERROR: bitshift exceeds the type's number of bits
40       let n = 1u64 >> 63;
41       let n = 1u64 >> 64; //~ ERROR: bitshift exceeds the type's number of bits
42       let n = 1i8 >> 7;
43       let n = 1i8 >> 8;   //~ ERROR: bitshift exceeds the type's number of bits
44       let n = 1i16 >> 15;
45       let n = 1i16 >> 16; //~ ERROR: bitshift exceeds the type's number of bits
46       let n = 1i32 >> 31;
47       let n = 1i32 >> 32; //~ ERROR: bitshift exceeds the type's number of bits
48       let n = 1i64 >> 63;
49       let n = 1i64 >> 64; //~ ERROR: bitshift exceeds the type's number of bits
50
51       let n = 1u8;
52       let n = n << 7;
53       let n = n << 8; //~ ERROR: bitshift exceeds the type's number of bits
54
55       let n = 1u8 << -8; //~ ERROR: bitshift exceeds the type's number of bits
56
57
58       let n = 1u8 << (4+3);
59       let n = 1u8 << (4+4); //~ ERROR: bitshift exceeds the type's number of bits
60
61       #[cfg(target_pointer_width = "32")]
62       const BITS: usize = 32;
63       #[cfg(target_pointer_width = "64")]
64       const BITS: usize = 64;
65
66       let n = 1_isize << BITS; //~ ERROR: bitshift exceeds the type's number of bits
67       let n = 1_usize << BITS; //~ ERROR: bitshift exceeds the type's number of bits
68
69
70       let n = 1i8<<(1isize+-1);
71
72       let n = 1i64 >> [63][0];
73       let n = 1i64 >> [64][0]; //~ ERROR: bitshift exceeds the type's number of bits
74 }