about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorFalco Hirschenberger <falco.hirschenberger@gmail.com>2014-08-05 09:59:03 +0200
committerFalco Hirschenberger <falco.hirschenberger@gmail.com>2014-08-05 09:59:03 +0200
commit0dc215741b34236c310e409c437600ba0165c97c (patch)
treebfaee6d4c3d1b082fadf859cb106b5e99d458028 /src/test
parent795f6ae829ab1bfd72394a5da9096e2717ec0f62 (diff)
downloadrust-0dc215741b34236c310e409c437600ba0165c97c.tar.gz
rust-0dc215741b34236c310e409c437600ba0165c97c.zip
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.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/compile-fail/lint-type-overflow.rs3
-rw-r--r--src/test/compile-fail/oversized-literal.rs6
-rw-r--r--src/test/run-pass/big-literals.rs2
3 files changed, 6 insertions, 5 deletions
diff --git a/src/test/compile-fail/lint-type-overflow.rs b/src/test/compile-fail/lint-type-overflow.rs
index 676a6e7cb44..c8179c3adb0 100644
--- a/src/test/compile-fail/lint-type-overflow.rs
+++ b/src/test/compile-fail/lint-type-overflow.rs
@@ -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
diff --git a/src/test/compile-fail/oversized-literal.rs b/src/test/compile-fail/oversized-literal.rs
index 0b5c6ac4fb3..5416bcacf3d 100644
--- a/src/test/compile-fail/oversized-literal.rs
+++ b/src/test/compile-fail/oversized-literal.rs
@@ -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
+}
diff --git a/src/test/run-pass/big-literals.rs b/src/test/run-pass/big-literals.rs
index c21ea343b16..8afb33c7669 100644
--- a/src/test/run-pass/big-literals.rs
+++ b/src/test/run-pass/big-literals.rs
@@ -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);
 }