]> git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/lint-type-overflow.rs
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / test / compile-fail / lint-type-overflow.rs
1 // Copyright 2013 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
12 #![deny(overflowing_literals)]
13
14 fn test(x: i8) {
15 println!("x {}", x);
16 }
17
18 #[allow(unused_variables)]
19 fn main() {
20 let x1: u8 = 255; // should be OK
21 let x1: u8 = 256; //~ error: literal out of range for u8
22
23 let x1 = 255_u8; // should be OK
24 let x1 = 256_u8; //~ error: literal out of range for u8
25
26 let x2: i8 = -128; // should be OK
27 let x1: i8 = 128; //~ error: literal out of range for i8
28
29 let x3: i8 = -129; //~ error: literal out of range for i8
30 let x3: i8 = -(129); //~ error: literal out of range for i8
31 let x3: i8 = -{129}; //~ error: literal out of range for i8
32
33 test(1000); //~ error: literal out of range for i8
34
35 let x = 128_i8; //~ error: literal out of range for i8
36 let x = 127_i8;
37 let x = -128_i8;
38 let x = -(128_i8);
39 let x = -129_i8; //~ error: literal out of range for i8
40
41 let x: i32 = 2147483647; // should be OK
42 let x = 2147483647_i32; // should be OK
43 let x: i32 = 2147483648; //~ error: literal out of range for i32
44 let x = 2147483648_i32; //~ error: literal out of range for i32
45 let x: i32 = -2147483648; // should be OK
46 let x = -2147483648_i32; // should be OK
47 let x: i32 = -2147483649; //~ error: literal out of range for i32
48 let x = -2147483649_i32; //~ error: literal out of range for i32
49 let x = 2147483648; //~ error: literal out of range for i32
50
51 let x = 9223372036854775808_i64; //~ error: literal out of range for i64
52 let x = -9223372036854775808_i64; // should be OK
53 let x = 18446744073709551615_i64; //~ error: literal out of range for i64
54 let x: i64 = -9223372036854775809; //~ error: literal out of range for i64
55 let x = -9223372036854775809_i64; //~ error: literal out of range for i64
56 }