Skip to content

Commit d5593ef

Browse files
committed
Rollup merge of #21815 - nagisa:overflowing-lints, r=alexcrichton
2 parents 9e42492 + afa526c commit d5593ef

File tree

3 files changed

+26
-25
lines changed

3 files changed

+26
-25
lines changed

src/librustc/lint/builtin.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ impl LintPass for TypeLimits {
227227
if (negative && v > (min.abs() as u64)) ||
228228
(!negative && v > (max.abs() as u64)) {
229229
cx.span_lint(OVERFLOWING_LITERALS, e.span,
230-
"literal out of range for its type");
230+
&*format!("literal out of range for {:?}", t));
231231
return;
232232
}
233233
}
@@ -246,7 +246,7 @@ impl LintPass for TypeLimits {
246246
};
247247
if lit_val < min || lit_val > max {
248248
cx.span_lint(OVERFLOWING_LITERALS, e.span,
249-
"literal out of range for its type");
249+
&*format!("literal out of range for {:?}", t));
250250
}
251251
},
252252
ty::ty_float(t) => {
@@ -263,7 +263,7 @@ impl LintPass for TypeLimits {
263263
};
264264
if lit_val < min || lit_val > max {
265265
cx.span_lint(OVERFLOWING_LITERALS, e.span,
266-
"literal out of range for its type");
266+
&*format!("literal out of range for {:?}", t));
267267
}
268268
},
269269
_ => ()

src/test/compile-fail/lint-type-limits.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn bar() -> i8 {
2626

2727
fn baz() -> bool {
2828
128 > bar() //~ ERROR comparison is useless due to type limits
29-
//~^ WARNING literal out of range for its type
29+
//~^ WARNING literal out of range for i8
3030
}
3131

3232
fn bleh() {
@@ -44,7 +44,7 @@ fn bleh() {
4444
fn qux() {
4545
let mut i = 1i8;
4646
while 200 != i { //~ ERROR comparison is useless due to type limits
47-
//~^ WARNING literal out of range for its type
47+
//~^ WARNING literal out of range for i8
4848
i += 1;
4949
}
5050
}

src/test/compile-fail/lint-type-overflow.rs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,42 +18,43 @@ fn test(x: i8) {
1818
#[allow(unused_variables)]
1919
fn main() {
2020
let x1: u8 = 255; // should be OK
21-
let x1: u8 = 256; //~ error: literal out of range for its type
21+
let x1: u8 = 256; //~ error: literal out of range for u8
2222

2323
let x1 = 255_u8; // should be OK
24-
let x1 = 256_u8; //~ error: literal out of range for its type
24+
let x1 = 256_u8; //~ error: literal out of range for u8
2525

2626
let x2: i8 = -128; // should be OK
27-
let x1: i8 = 128; //~ error: literal out of range for its type
28-
let x2: i8 = --128; //~ error: literal out of range for its type
27+
let x1: i8 = 128; //~ error: literal out of range for i8
28+
let x2: i8 = --128; //~ error: literal out of range for i8
2929

30-
let x3: i8 = -129; //~ error: literal out of range for its type
31-
let x3: i8 = -(129); //~ error: literal out of range for its type
32-
let x3: i8 = -{129}; //~ error: literal out of range for its type
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+
let x3: i8 = -{129}; //~ error: literal out of range for i8
3333

34-
test(1000); //~ error: literal out of range for its type
34+
test(1000); //~ error: literal out of range for i8
3535

36-
let x = 128_i8; //~ error: literal out of range for its type
36+
let x = 128_i8; //~ error: literal out of range for i8
3737
let x = 127_i8;
3838
let x = -128_i8;
3939
let x = -(128_i8);
40-
let x = -129_i8; //~ error: literal out of range for its type
40+
let x = -129_i8; //~ error: literal out of range for i8
4141

4242
let x: i32 = 2147483647; // should be OK
4343
let x = 2147483647_i32; // should be OK
44-
let x: i32 = 2147483648; //~ error: literal out of range for its type
45-
let x = 2147483648_i32; //~ error: literal out of range for its type
44+
let x: i32 = 2147483648; //~ error: literal out of range for i32
45+
let x = 2147483648_i32; //~ error: literal out of range for i32
4646
let x: i32 = -2147483648; // should be OK
4747
let x = -2147483648_i32; // should be OK
48-
let x: i32 = -2147483649; //~ error: literal out of range for its type
49-
let x = -2147483649_i32; //~ error: literal out of range for its type
48+
let x: i32 = -2147483649; //~ error: literal out of range for i32
49+
let x = -2147483649_i32; //~ error: literal out of range for i32
50+
let x = 2147483648; //~ error: literal out of range for i32
5051

51-
let x = 9223372036854775808_i64; //~ error: literal out of range for its type
52+
let x = 9223372036854775808_i64; //~ error: literal out of range for i64
5253
let x = -9223372036854775808_i64; // should be OK
53-
let x = 18446744073709551615_i64; //~ error: literal out of range for its type
54+
let x = 18446744073709551615_i64; //~ error: literal out of range for i64
5455

55-
let x = -3.40282348e+38_f32; //~ error: literal out of range for its type
56-
let x = 3.40282348e+38_f32; //~ error: literal out of range for its type
57-
let x = -1.7976931348623159e+308_f64; //~ error: literal out of range for its type
58-
let x = 1.7976931348623159e+308_f64; //~ error: literal out of range for its type
56+
let x = -3.40282348e+38_f32; //~ error: literal out of range for f32
57+
let x = 3.40282348e+38_f32; //~ error: literal out of range for f32
58+
let x = -1.7976931348623159e+308_f64; //~ error: literal out of range for f64
59+
let x = 1.7976931348623159e+308_f64; //~ error: literal out of range for f64
5960
}

0 commit comments

Comments
 (0)