Fixes missing overflow lint for i64 #14269

The `type_overflow` lint, doesn't catch the overflow for `i64` because
the overflow happens earlier in the parse phase when the `u64` as biggest
possible int gets casted to `i64` , without checking the for overflows.
We can't lint in the parse phase, so a refactoring of the `LitInt` type
was necessary.

The types `LitInt`, `LitUint` and `LitIntUnsuffixed` where merged to one
type `LitInt` which stores it's value as `u64`. An additional parameter was
added which indicate the signedness of the type and the sign of the value.
This commit is contained in:
Falco Hirschenberger 2014-08-05 09:59:03 +02:00
parent 795f6ae829
commit 0dc215741b
18 changed files with 142 additions and 99 deletions

View file

@ -48,6 +48,9 @@ fn main() {
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 = 9223372036854775808_i64; //~ error: literal out of range for its type
let x = 18446744073709551615_i64; //~ error: literal out of range for its type
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

View file

@ -8,6 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// compile-flags: -D type-overflow
fn main() { println!("{}", 300u8); } //~ error: literal out of range for its type
fn main() {
println!("{}", 18446744073709551616u64); //~ error: int literal is too large
}

View file

@ -15,6 +15,4 @@ pub fn main() {
assert_eq!(18446744073709551615u64, (-1 as u64));
assert_eq!(-2147483648i32 - 1i32, 2147483647i32);
assert_eq!(-9223372036854775808i64 - 1i64, 9223372036854775807i64);
assert_eq!(-9223372036854775808i - 1, 9223372036854775807);
}