diff options
| author | Ralf Jung <post@ralfj.de> | 2020-02-10 11:37:02 +0100 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2020-02-10 11:37:02 +0100 |
| commit | d6c5a04eff9643b634cb2c98411f973b8f7aa1e2 (patch) | |
| tree | 51a4701312b5e8cf4d14549eb0fc2d8e2449a4c2 | |
| parent | 1ddb0503ff1e203de40f5bbc1e0b00d1b4e99d12 (diff) | |
| download | rust-d6c5a04eff9643b634cb2c98411f973b8f7aa1e2.tar.gz rust-d6c5a04eff9643b634cb2c98411f973b8f7aa1e2.zip | |
some more tests for i128 oveflow behavior
| -rw-r--r-- | src/test/ui/consts/const-err2.rs | 8 | ||||
| -rw-r--r-- | src/test/ui/consts/const-err2.stderr | 22 | ||||
| -rw-r--r-- | src/test/ui/consts/const-err3.rs | 6 | ||||
| -rw-r--r-- | src/test/ui/consts/const-err3.stderr | 22 | ||||
| -rw-r--r-- | src/test/ui/consts/const-int-arithmetic.rs | 21 |
5 files changed, 66 insertions, 13 deletions
diff --git a/src/test/ui/consts/const-err2.rs b/src/test/ui/consts/const-err2.rs index 351dfd2e0f5..7c5aaedda35 100644 --- a/src/test/ui/consts/const-err2.rs +++ b/src/test/ui/consts/const-err2.rs @@ -17,16 +17,22 @@ fn black_box<T>(_: T) { fn main() { let a = -std::i8::MIN; //~^ ERROR const_err + let a_i128 = -std::i128::MIN; + //~^ ERROR const_err let b = 200u8 + 200u8 + 200u8; //~^ ERROR const_err + let b_i128 = std::i128::MIN - std::i128::MAX; + //~^ ERROR const_err let c = 200u8 * 4; //~^ ERROR const_err let d = 42u8 - (42u8 + 1); //~^ ERROR const_err let _e = [5u8][1]; - //~^ ERROR index out of bounds + //~^ ERROR const_err black_box(a); + black_box(a_i128); black_box(b); + black_box(b_i128); black_box(c); black_box(d); } diff --git a/src/test/ui/consts/const-err2.stderr b/src/test/ui/consts/const-err2.stderr index a76b6d1775f..f135bf0b06c 100644 --- a/src/test/ui/consts/const-err2.stderr +++ b/src/test/ui/consts/const-err2.stderr @@ -11,28 +11,40 @@ LL | #![deny(const_err)] | ^^^^^^^^^ error: this expression will panic at runtime - --> $DIR/const-err2.rs:20:13 + --> $DIR/const-err2.rs:20:18 + | +LL | let a_i128 = -std::i128::MIN; + | ^^^^^^^^^^^^^^^ attempt to negate with overflow + +error: this expression will panic at runtime + --> $DIR/const-err2.rs:22:13 | LL | let b = 200u8 + 200u8 + 200u8; | ^^^^^^^^^^^^^ attempt to add with overflow error: this expression will panic at runtime - --> $DIR/const-err2.rs:22:13 + --> $DIR/const-err2.rs:24:18 + | +LL | let b_i128 = std::i128::MIN - std::i128::MAX; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to subtract with overflow + +error: this expression will panic at runtime + --> $DIR/const-err2.rs:26:13 | LL | let c = 200u8 * 4; | ^^^^^^^^^ attempt to multiply with overflow error: this expression will panic at runtime - --> $DIR/const-err2.rs:24:13 + --> $DIR/const-err2.rs:28:13 | LL | let d = 42u8 - (42u8 + 1); | ^^^^^^^^^^^^^^^^^ attempt to subtract with overflow error: index out of bounds: the len is 1 but the index is 1 - --> $DIR/const-err2.rs:26:14 + --> $DIR/const-err2.rs:30:14 | LL | let _e = [5u8][1]; | ^^^^^^^^ -error: aborting due to 5 previous errors +error: aborting due to 7 previous errors diff --git a/src/test/ui/consts/const-err3.rs b/src/test/ui/consts/const-err3.rs index ab3823efd30..43aba4a8b01 100644 --- a/src/test/ui/consts/const-err3.rs +++ b/src/test/ui/consts/const-err3.rs @@ -17,8 +17,12 @@ fn black_box<T>(_: T) { fn main() { let a = -std::i8::MIN; //~^ ERROR const_err + let a_i128 = -std::i128::MIN; + //~^ ERROR const_err let b = 200u8 + 200u8 + 200u8; //~^ ERROR const_err + let b_i128 = std::i128::MIN - std::i128::MAX; + //~^ ERROR const_err let c = 200u8 * 4; //~^ ERROR const_err let d = 42u8 - (42u8 + 1); @@ -26,7 +30,9 @@ fn main() { let _e = [5u8][1]; //~^ ERROR const_err black_box(a); + black_box(a_i128); black_box(b); + black_box(b_i128); black_box(c); black_box(d); } diff --git a/src/test/ui/consts/const-err3.stderr b/src/test/ui/consts/const-err3.stderr index 02b912e928c..05f64b87fcc 100644 --- a/src/test/ui/consts/const-err3.stderr +++ b/src/test/ui/consts/const-err3.stderr @@ -10,29 +10,41 @@ note: the lint level is defined here LL | #![deny(const_err)] | ^^^^^^^^^ +error: attempt to negate with overflow + --> $DIR/const-err3.rs:20:18 + | +LL | let a_i128 = -std::i128::MIN; + | ^^^^^^^^^^^^^^^ + error: attempt to add with overflow - --> $DIR/const-err3.rs:20:13 + --> $DIR/const-err3.rs:22:13 | LL | let b = 200u8 + 200u8 + 200u8; | ^^^^^^^^^^^^^ +error: attempt to subtract with overflow + --> $DIR/const-err3.rs:24:18 + | +LL | let b_i128 = std::i128::MIN - std::i128::MAX; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + error: attempt to multiply with overflow - --> $DIR/const-err3.rs:22:13 + --> $DIR/const-err3.rs:26:13 | LL | let c = 200u8 * 4; | ^^^^^^^^^ error: attempt to subtract with overflow - --> $DIR/const-err3.rs:24:13 + --> $DIR/const-err3.rs:28:13 | LL | let d = 42u8 - (42u8 + 1); | ^^^^^^^^^^^^^^^^^ error: index out of bounds: the len is 1 but the index is 1 - --> $DIR/const-err3.rs:26:14 + --> $DIR/const-err3.rs:30:14 | LL | let _e = [5u8][1]; | ^^^^^^^^ -error: aborting due to 5 previous errors +error: aborting due to 7 previous errors diff --git a/src/test/ui/consts/const-int-arithmetic.rs b/src/test/ui/consts/const-int-arithmetic.rs index cfa2873c68b..2c3421b7a8d 100644 --- a/src/test/ui/consts/const-int-arithmetic.rs +++ b/src/test/ui/consts/const-int-arithmetic.rs @@ -7,7 +7,7 @@ #![feature(const_saturating_int_methods)] #![feature(const_wrapping_int_methods)] -use std::i8; +use std::{i8, i128}; macro_rules! suite { ($( @@ -65,6 +65,10 @@ suite!( C26: 5i8.checked_rem_euclid(0), None; C27: i8::MIN.checked_rem_euclid(-1), None; } + checked_i128 -> Option<i128> { + CHK_ADD_I128: i128::MAX.checked_add(1), None; + CHK_MUL_I128: i128::MIN.checked_mul(-1), None; + } saturating_and_wrapping -> i8 { // `const_saturating_int_methods` @@ -104,6 +108,13 @@ suite!( C47: 100i8.wrapping_rem_euclid(10), 0; C48: (-128i8).wrapping_rem_euclid(-1), 0; } + saturating_and_wrapping_i128 -> i128 { + SAT_ADD_I128: i128::MAX.saturating_add(1), i128::MAX; + SAT_MUL_I128: i128::MAX.saturating_mul(2), i128::MAX; + + WRP_ADD_I128: i128::MAX.wrapping_add(1), i128::MIN; + WRP_MUL_I128: i128::MAX.wrapping_mul(3), i128::MAX-2; + } overflowing -> (i8, bool) { // `const_overflowing_int_methods` @@ -119,12 +130,18 @@ suite!( C55: 5i8.overflowing_rem_euclid(2), (1, false); C56: i8::MIN.overflowing_rem_euclid(-1), (0, true); - + } + overflowing_i128 -> (i128, bool) { + OFL_ADD_I128: i128::MAX.overflowing_add(1), (i128::MIN, true); + OFL_MUL_I128: i128::MAX.overflowing_mul(3), (i128::MAX-2, true); } ); fn main() { checked(); + checked_i128(); saturating_and_wrapping(); + saturating_and_wrapping_i128(); overflowing(); + overflowing_i128(); } |
