rollup merge of #21815: nagisa/overflowing-lints

This commit is contained in:
Alex Crichton 2015-02-02 10:58:09 -08:00
commit 22fdf97035
3 changed files with 26 additions and 25 deletions

View File

@ -227,7 +227,7 @@ impl LintPass for TypeLimits {
if (negative && v > (min.abs() as u64)) ||
(!negative && v > (max.abs() as u64)) {
cx.span_lint(OVERFLOWING_LITERALS, e.span,
"literal out of range for its type");
&*format!("literal out of range for {:?}", t));
return;
}
}
@ -246,7 +246,7 @@ impl LintPass for TypeLimits {
};
if lit_val < min || lit_val > max {
cx.span_lint(OVERFLOWING_LITERALS, e.span,
"literal out of range for its type");
&*format!("literal out of range for {:?}", t));
}
},
ty::ty_float(t) => {
@ -263,7 +263,7 @@ impl LintPass for TypeLimits {
};
if lit_val < min || lit_val > max {
cx.span_lint(OVERFLOWING_LITERALS, e.span,
"literal out of range for its type");
&*format!("literal out of range for {:?}", t));
}
},
_ => ()

View File

@ -26,7 +26,7 @@ fn bar() -> i8 {
fn baz() -> bool {
128 > bar() //~ ERROR comparison is useless due to type limits
//~^ WARNING literal out of range for its type
//~^ WARNING literal out of range for i8
}
fn bleh() {
@ -44,7 +44,7 @@ fn bleh() {
fn qux() {
let mut i = 1i8;
while 200 != i { //~ ERROR comparison is useless due to type limits
//~^ WARNING literal out of range for its type
//~^ WARNING literal out of range for i8
i += 1;
}
}

View File

@ -18,42 +18,43 @@ fn test(x: i8) {
#[allow(unused_variables)]
fn main() {
let x1: u8 = 255; // should be OK
let x1: u8 = 256; //~ error: literal out of range for its type
let x1: u8 = 256; //~ error: literal out of range for u8
let x1 = 255_u8; // should be OK
let x1 = 256_u8; //~ error: literal out of range for its type
let x1 = 256_u8; //~ error: literal out of range for u8
let x2: i8 = -128; // should be OK
let x1: i8 = 128; //~ error: literal out of range for its type
let x2: i8 = --128; //~ error: literal out of range for its type
let x1: i8 = 128; //~ error: literal out of range for i8
let x2: i8 = --128; //~ error: literal out of range for i8
let x3: i8 = -129; //~ error: literal out of range for its type
let x3: i8 = -(129); //~ error: literal out of range for its type
let x3: i8 = -{129}; //~ error: literal out of range for its type
let x3: i8 = -129; //~ error: literal out of range for i8
let x3: i8 = -(129); //~ error: literal out of range for i8
let x3: i8 = -{129}; //~ error: literal out of range for i8
test(1000); //~ error: literal out of range for its type
test(1000); //~ error: literal out of range for i8
let x = 128_i8; //~ error: literal out of range for its type
let x = 128_i8; //~ error: literal out of range for i8
let x = 127_i8;
let x = -128_i8;
let x = -(128_i8);
let x = -129_i8; //~ error: literal out of range for its type
let x = -129_i8; //~ error: literal out of range for i8
let x: i32 = 2147483647; // should be OK
let x = 2147483647_i32; // should be OK
let x: i32 = 2147483648; //~ error: literal out of range for its type
let x = 2147483648_i32; //~ error: literal out of range for its type
let x: i32 = 2147483648; //~ error: literal out of range for i32
let x = 2147483648_i32; //~ error: literal out of range for i32
let x: i32 = -2147483648; // should be OK
let x = -2147483648_i32; // should be OK
let x: i32 = -2147483649; //~ error: literal out of range for its type
let x = -2147483649_i32; //~ error: literal out of range for its type
let x: i32 = -2147483649; //~ error: literal out of range for i32
let x = -2147483649_i32; //~ error: literal out of range for i32
let x = 2147483648; //~ error: literal out of range for i32
let x = 9223372036854775808_i64; //~ error: literal out of range for its type
let x = 9223372036854775808_i64; //~ error: literal out of range for i64
let x = -9223372036854775808_i64; // should be OK
let x = 18446744073709551615_i64; //~ error: literal out of range for its type
let x = 18446744073709551615_i64; //~ error: literal out of range for i64
let x = -3.40282348e+38_f32; //~ error: literal out of range for its type
let x = 3.40282348e+38_f32; //~ error: literal out of range for its type
let x = -1.7976931348623159e+308_f64; //~ error: literal out of range for its type
let x = 1.7976931348623159e+308_f64; //~ error: literal out of range for its type
let x = -3.40282348e+38_f32; //~ error: literal out of range for f32
let x = 3.40282348e+38_f32; //~ error: literal out of range for f32
let x = -1.7976931348623159e+308_f64; //~ error: literal out of range for f64
let x = 1.7976931348623159e+308_f64; //~ error: literal out of range for f64
}