Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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) => {
Expand All @@ -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));
}
},
_ => ()
Expand Down
4 changes: 2 additions & 2 deletions src/test/compile-fail/lint-type-limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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;
}
}
Expand Down
41 changes: 21 additions & 20 deletions src/test/compile-fail/lint-type-overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}