Migrate to numeric associated consts
This commit is contained in:
parent
283522400b
commit
fff822fead
101 changed files with 485 additions and 518 deletions
|
|
@ -1,6 +1,6 @@
|
|||
enum Foo {
|
||||
// test that we detect overflows for non-u32 discriminants
|
||||
X = 1 << ((u32::max_value() as u64) + 1), //~ ERROR E0080
|
||||
X = 1 << ((u32::MAX as u64) + 1), //~ ERROR E0080
|
||||
Y = 42,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
error[E0080]: evaluation of constant value failed
|
||||
--> $DIR/shift_overflow.rs:3:9
|
||||
|
|
||||
LL | X = 1 << ((u32::max_value() as u64) + 1),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to shift left with overflow
|
||||
LL | X = 1 << ((u32::MAX as u64) + 1),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to shift left with overflow
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -34,8 +34,8 @@ suite!(
|
|||
C6: 5i8.checked_mul(122), None;
|
||||
C7: (-127i8).checked_mul(-99), None;
|
||||
|
||||
C8: (i8::min_value() + 1).checked_div(-1), Some(127);
|
||||
C9: i8::min_value().checked_div(-1), None;
|
||||
C8: (i8::MIN + 1).checked_div(-1), Some(127);
|
||||
C9: i8::MIN.checked_div(-1), None;
|
||||
C10: 1i8.checked_div(0), None;
|
||||
|
||||
C11: 5i8.checked_rem(2), Some(1);
|
||||
|
|
@ -56,8 +56,8 @@ suite!(
|
|||
C21: i8::MIN.checked_abs(), None;
|
||||
|
||||
// `const_euclidean_int_methods`
|
||||
C22: (i8::min_value() + 1).checked_div_euclid(-1), Some(127);
|
||||
C23: i8::min_value().checked_div_euclid(-1), None;
|
||||
C22: (i8::MIN + 1).checked_div_euclid(-1), Some(127);
|
||||
C23: i8::MIN.checked_div_euclid(-1), None;
|
||||
C24: (1i8).checked_div_euclid(0), None;
|
||||
|
||||
C25: 5i8.checked_rem_euclid(2), Some(1);
|
||||
|
|
@ -72,12 +72,12 @@ suite!(
|
|||
saturating_and_wrapping -> i8 {
|
||||
// `const_saturating_int_methods`
|
||||
C28: 100i8.saturating_add(1), 101;
|
||||
C29: i8::max_value().saturating_add(100), i8::max_value();
|
||||
C30: i8::min_value().saturating_add(-1), i8::min_value();
|
||||
C29: i8::MAX.saturating_add(100), i8::MAX;
|
||||
C30: i8::MIN.saturating_add(-1), i8::MIN;
|
||||
|
||||
C31: 100i8.saturating_sub(127), -27;
|
||||
C32: i8::min_value().saturating_sub(100), i8::min_value();
|
||||
C33: i8::max_value().saturating_sub(-1), i8::max_value();
|
||||
C32: i8::MIN.saturating_sub(100), i8::MIN;
|
||||
C33: i8::MAX.saturating_sub(-1), i8::MAX;
|
||||
|
||||
C34: 10i8.saturating_mul(12), 120;
|
||||
C35: i8::MAX.saturating_mul(10), i8::MAX;
|
||||
|
|
@ -85,13 +85,13 @@ suite!(
|
|||
|
||||
C37: 100i8.saturating_neg(), -100;
|
||||
C38: (-100i8).saturating_neg(), 100;
|
||||
C39: i8::min_value().saturating_neg(), i8::max_value();
|
||||
C40: i8::max_value().saturating_neg(), i8::min_value() + 1;
|
||||
C39: i8::MIN.saturating_neg(), i8::MAX;
|
||||
C40: i8::MAX.saturating_neg(), i8::MIN + 1;
|
||||
|
||||
C57: 100i8.saturating_abs(), 100;
|
||||
C58: (-100i8).saturating_abs(), 100;
|
||||
C59: i8::min_value().saturating_abs(), i8::max_value();
|
||||
C60: (i8::min_value() + 1).saturating_abs(), i8::max_value();
|
||||
C59: i8::MIN.saturating_abs(), i8::MAX;
|
||||
C60: (i8::MIN + 1).saturating_abs(), i8::MAX;
|
||||
|
||||
// `const_wrapping_int_methods`
|
||||
C41: 100i8.wrapping_div(10), 10;
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@ const FROM_LE_BYTES: i32 = i32::from_le_bytes([0x12, 0x34, 0x56, 0x78]);
|
|||
const FROM_NE_BYTES: i32 = i32::from_be(i32::from_ne_bytes([0x80, 0, 0, 0]));
|
||||
const TO_BE_BYTES: [u8; 4] = 0x12_34_56_78_i32.to_be_bytes();
|
||||
const TO_LE_BYTES: [u8; 4] = 0x12_34_56_78_i32.to_le_bytes();
|
||||
const TO_NE_BYTES: [u8; 4] = i32::min_value().to_be().to_ne_bytes();
|
||||
const TO_NE_BYTES: [u8; 4] = i32::MIN.to_be().to_ne_bytes();
|
||||
|
||||
fn main() {
|
||||
assert_eq!(REVERSE, 0x1e6a2c48);
|
||||
assert_eq!(FROM_BE_BYTES, 0x12_34_56_78);
|
||||
assert_eq!(FROM_LE_BYTES, 0x78_56_34_12);
|
||||
assert_eq!(FROM_NE_BYTES, i32::min_value());
|
||||
assert_eq!(FROM_NE_BYTES, i32::MIN);
|
||||
assert_eq!(TO_BE_BYTES, [0x12, 0x34, 0x56, 0x78]);
|
||||
assert_eq!(TO_LE_BYTES, [0x78, 0x56, 0x34, 0x12]);
|
||||
assert_eq!(TO_NE_BYTES, [0x80, 0, 0, 0]);
|
||||
|
|
|
|||
|
|
@ -11,6 +11,6 @@ fn main() {
|
|||
//~^ ERROR temporary value dropped while borrowed
|
||||
let c: &'static [u8] = &(0x12_34_56_78_i32.to_le_bytes());
|
||||
//~^ ERROR temporary value dropped while borrowed
|
||||
let d: &'static [u8] = &(i32::min_value().to_be().to_ne_bytes());
|
||||
let d: &'static [u8] = &(i32::MIN.to_be().to_ne_bytes());
|
||||
//~^ ERROR temporary value dropped while borrowed
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,8 +67,8 @@ LL | }
|
|||
error[E0716]: temporary value dropped while borrowed
|
||||
--> $DIR/const-int-conversion.rs:14:29
|
||||
|
|
||||
LL | let d: &'static [u8] = &(i32::min_value().to_be().to_ne_bytes());
|
||||
| ------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
|
||||
LL | let d: &'static [u8] = &(i32::MIN.to_be().to_ne_bytes());
|
||||
| ------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
|
||||
| |
|
||||
| type annotation requires that borrow lasts for `'static`
|
||||
LL |
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// run-pass
|
||||
|
||||
const ADD_A: (u32, bool) = 5u32.overflowing_add(2);
|
||||
const ADD_B: (u32, bool) = u32::max_value().overflowing_add(1);
|
||||
const ADD_B: (u32, bool) = u32::MAX.overflowing_add(1);
|
||||
|
||||
const SUB_A: (u32, bool) = 5u32.overflowing_sub(2);
|
||||
const SUB_B: (u32, bool) = 0u32.overflowing_sub(1);
|
||||
|
|
@ -20,14 +20,14 @@ const NEG_B: (u32, bool) = core::u32::MAX.overflowing_neg();
|
|||
|
||||
const ABS_POS: (i32, bool) = 10i32.overflowing_abs();
|
||||
const ABS_NEG: (i32, bool) = (-10i32).overflowing_abs();
|
||||
const ABS_MIN: (i32, bool) = i32::min_value().overflowing_abs();
|
||||
const ABS_MIN: (i32, bool) = i32::MIN.overflowing_abs();
|
||||
|
||||
fn main() {
|
||||
assert_eq!(ADD_A, (7, false));
|
||||
assert_eq!(ADD_B, (0, true));
|
||||
|
||||
assert_eq!(SUB_A, (3, false));
|
||||
assert_eq!(SUB_B, (u32::max_value(), true));
|
||||
assert_eq!(SUB_B, (u32::MAX, true));
|
||||
|
||||
assert_eq!(MUL_A, (10, false));
|
||||
assert_eq!(MUL_B, (1410065408, true));
|
||||
|
|
@ -43,5 +43,5 @@ fn main() {
|
|||
|
||||
assert_eq!(ABS_POS, (10, false));
|
||||
assert_eq!(ABS_NEG, (10, false));
|
||||
assert_eq!(ABS_MIN, (i32::min_value(), true));
|
||||
assert_eq!(ABS_MIN, (i32::MIN, true));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,10 +20,10 @@ const NEXT_POWER_OF_TWO: u32 = 3u32.next_power_of_two();
|
|||
|
||||
const CHECKED_NEXT_POWER_OF_TWO_OK: Option<u32> = 3u32.checked_next_power_of_two();
|
||||
const CHECKED_NEXT_POWER_OF_TWO_OVERFLOW: Option<u32> =
|
||||
u32::max_value().checked_next_power_of_two();
|
||||
u32::MAX.checked_next_power_of_two();
|
||||
|
||||
const WRAPPING_NEXT_POWER_OF_TWO: u32 =
|
||||
u32::max_value().wrapping_next_power_of_two();
|
||||
u32::MAX.wrapping_next_power_of_two();
|
||||
|
||||
fn main() {
|
||||
assert!(!IS_POWER_OF_TWO_A);
|
||||
|
|
@ -37,7 +37,7 @@ fn main() {
|
|||
|
||||
assert_eq!(WRAPPING_POW, 217);
|
||||
assert_eq!(OVERFLOWING_POW, (217, true));
|
||||
assert_eq!(SATURATING_POW, u8::max_value());
|
||||
assert_eq!(SATURATING_POW, u8::MAX);
|
||||
|
||||
assert_eq!(NEXT_POWER_OF_TWO, 4);
|
||||
|
||||
|
|
|
|||
|
|
@ -2,33 +2,33 @@
|
|||
#![feature(const_saturating_int_methods)]
|
||||
|
||||
const INT_U32_NO: u32 = (42 as u32).saturating_add(2);
|
||||
const INT_U32: u32 = u32::max_value().saturating_add(1);
|
||||
const INT_U128: u128 = u128::max_value().saturating_add(1);
|
||||
const INT_I128: i128 = i128::max_value().saturating_add(1);
|
||||
const INT_I128_NEG: i128 = i128::min_value().saturating_add(-1);
|
||||
const INT_U32: u32 = u32::MAX.saturating_add(1);
|
||||
const INT_U128: u128 = u128::MAX.saturating_add(1);
|
||||
const INT_I128: i128 = i128::MAX.saturating_add(1);
|
||||
const INT_I128_NEG: i128 = i128::MIN.saturating_add(-1);
|
||||
|
||||
const INT_U32_NO_SUB: u32 = (42 as u32).saturating_sub(2);
|
||||
const INT_U32_SUB: u32 = (1 as u32).saturating_sub(2);
|
||||
const INT_I32_NO_SUB: i32 = (-42 as i32).saturating_sub(2);
|
||||
const INT_I32_NEG_SUB: i32 = i32::min_value().saturating_sub(1);
|
||||
const INT_I32_POS_SUB: i32 = i32::max_value().saturating_sub(-1);
|
||||
const INT_I32_NEG_SUB: i32 = i32::MIN.saturating_sub(1);
|
||||
const INT_I32_POS_SUB: i32 = i32::MAX.saturating_sub(-1);
|
||||
const INT_U128_SUB: u128 = (0 as u128).saturating_sub(1);
|
||||
const INT_I128_NEG_SUB: i128 = i128::min_value().saturating_sub(1);
|
||||
const INT_I128_POS_SUB: i128 = i128::max_value().saturating_sub(-1);
|
||||
const INT_I128_NEG_SUB: i128 = i128::MIN.saturating_sub(1);
|
||||
const INT_I128_POS_SUB: i128 = i128::MAX.saturating_sub(-1);
|
||||
|
||||
fn main() {
|
||||
assert_eq!(INT_U32_NO, 44);
|
||||
assert_eq!(INT_U32, u32::max_value());
|
||||
assert_eq!(INT_U128, u128::max_value());
|
||||
assert_eq!(INT_I128, i128::max_value());
|
||||
assert_eq!(INT_I128_NEG, i128::min_value());
|
||||
assert_eq!(INT_U32, u32::MAX);
|
||||
assert_eq!(INT_U128, u128::MAX);
|
||||
assert_eq!(INT_I128, i128::MAX);
|
||||
assert_eq!(INT_I128_NEG, i128::MIN);
|
||||
|
||||
assert_eq!(INT_U32_NO_SUB, 40);
|
||||
assert_eq!(INT_U32_SUB, 0);
|
||||
assert_eq!(INT_I32_NO_SUB, -44);
|
||||
assert_eq!(INT_I32_NEG_SUB, i32::min_value());
|
||||
assert_eq!(INT_I32_POS_SUB, i32::max_value());
|
||||
assert_eq!(INT_I32_NEG_SUB, i32::MIN);
|
||||
assert_eq!(INT_I32_POS_SUB, i32::MAX);
|
||||
assert_eq!(INT_U128_SUB, 0);
|
||||
assert_eq!(INT_I128_NEG_SUB, i128::min_value());
|
||||
assert_eq!(INT_I128_POS_SUB, i128::max_value());
|
||||
assert_eq!(INT_I128_NEG_SUB, i128::MIN);
|
||||
assert_eq!(INT_I128_POS_SUB, i128::MAX);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -131,12 +131,12 @@ const _: u16 = unsafe { std::intrinsics::unchecked_mul(300u16, 250u16) };
|
|||
|
||||
const _: i32 = unsafe { std::intrinsics::unchecked_div(1, 0) };
|
||||
//~^ ERROR any use of this value will cause an error
|
||||
const _: i32 = unsafe { std::intrinsics::unchecked_div(i32::min_value(), -1) };
|
||||
const _: i32 = unsafe { std::intrinsics::unchecked_div(i32::MIN, -1) };
|
||||
//~^ ERROR any use of this value will cause an error
|
||||
|
||||
const _: i32 = unsafe { std::intrinsics::unchecked_rem(1, 0) };
|
||||
//~^ ERROR any use of this value will cause an error
|
||||
const _: i32 = unsafe { std::intrinsics::unchecked_rem(i32::min_value(), -1) };
|
||||
const _: i32 = unsafe { std::intrinsics::unchecked_rem(i32::MIN, -1) };
|
||||
//~^ ERROR any use of this value will cause an error
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -355,8 +355,8 @@ LL | const _: i32 = unsafe { std::intrinsics::unchecked_div(1, 0) };
|
|||
error: any use of this value will cause an error
|
||||
--> $DIR/const-int-unchecked.rs:134:25
|
||||
|
|
||||
LL | const _: i32 = unsafe { std::intrinsics::unchecked_div(i32::min_value(), -1) };
|
||||
| ------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---
|
||||
LL | const _: i32 = unsafe { std::intrinsics::unchecked_div(i32::MIN, -1) };
|
||||
| ------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---
|
||||
| |
|
||||
| overflow executing `unchecked_div`
|
||||
|
||||
|
|
@ -371,8 +371,8 @@ LL | const _: i32 = unsafe { std::intrinsics::unchecked_rem(1, 0) };
|
|||
error: any use of this value will cause an error
|
||||
--> $DIR/const-int-unchecked.rs:139:25
|
||||
|
|
||||
LL | const _: i32 = unsafe { std::intrinsics::unchecked_rem(i32::min_value(), -1) };
|
||||
| ------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---
|
||||
LL | const _: i32 = unsafe { std::intrinsics::unchecked_rem(i32::MIN, -1) };
|
||||
| ------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---
|
||||
| |
|
||||
| overflow executing `unchecked_rem`
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
// run-pass
|
||||
|
||||
const ADD_A: u32 = 200u32.wrapping_add(55);
|
||||
const ADD_B: u32 = 200u32.wrapping_add(u32::max_value());
|
||||
const ADD_B: u32 = 200u32.wrapping_add(u32::MAX);
|
||||
|
||||
const SUB_A: u32 = 100u32.wrapping_sub(100);
|
||||
const SUB_B: u32 = 100u32.wrapping_sub(u32::max_value());
|
||||
const SUB_B: u32 = 100u32.wrapping_sub(u32::MAX);
|
||||
|
||||
const MUL_A: u8 = 10u8.wrapping_mul(12);
|
||||
const MUL_B: u8 = 25u8.wrapping_mul(12);
|
||||
|
|
@ -20,7 +20,7 @@ const NEG_B: u32 = 1234567890u32.wrapping_neg();
|
|||
|
||||
const ABS_POS: i32 = 10i32.wrapping_abs();
|
||||
const ABS_NEG: i32 = (-10i32).wrapping_abs();
|
||||
const ABS_MIN: i32 = i32::min_value().wrapping_abs();
|
||||
const ABS_MIN: i32 = i32::MIN.wrapping_abs();
|
||||
|
||||
fn main() {
|
||||
assert_eq!(ADD_A, 255);
|
||||
|
|
@ -43,5 +43,5 @@ fn main() {
|
|||
|
||||
assert_eq!(ABS_POS, 10);
|
||||
assert_eq!(ABS_NEG, 10);
|
||||
assert_eq!(ABS_MIN, i32::min_value());
|
||||
assert_eq!(ABS_MIN, i32::MIN);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
#[repr(i128)]
|
||||
enum Test {
|
||||
A(Box<u64>) = 0,
|
||||
B(usize) = u64::max_value() as i128 + 1,
|
||||
B(usize) = u64::MAX as i128 + 1,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ use std::marker::DiscriminantKind;
|
|||
enum Signed {
|
||||
Zero = 0,
|
||||
Staircase = 0x01_02_03_04_05_06_07_08_09_0a_0b_0c_0d_0e_0f,
|
||||
U64Limit = u64::max_value() as i128 + 1,
|
||||
U64Limit = u64::MAX as i128 + 1,
|
||||
SmallNegative = -1,
|
||||
BigNegative = i128::min_value(),
|
||||
BigNegative = i128::MIN,
|
||||
Next,
|
||||
}
|
||||
|
||||
|
|
@ -18,7 +18,7 @@ enum Signed {
|
|||
enum Unsigned {
|
||||
Zero = 0,
|
||||
Staircase = 0x01_02_03_04_05_06_07_08_09_0a_0b_0c_0d_0e_0f,
|
||||
U64Limit = u64::max_value() as u128 + 1,
|
||||
U64Limit = u64::MAX as u128 + 1,
|
||||
Next,
|
||||
}
|
||||
|
||||
|
|
@ -32,13 +32,13 @@ where
|
|||
fn main() {
|
||||
discr(Signed::Zero, 0);
|
||||
discr(Signed::Staircase, 0x01_02_03_04_05_06_07_08_09_0a_0b_0c_0d_0e_0f);
|
||||
discr(Signed::U64Limit, u64::max_value() as i128 + 1);
|
||||
discr(Signed::U64Limit, u64::MAX as i128 + 1);
|
||||
discr(Signed::SmallNegative, -1);
|
||||
discr(Signed::BigNegative, i128::min_value());
|
||||
discr(Signed::Next, i128::min_value() + 1);
|
||||
discr(Signed::BigNegative, i128::MIN);
|
||||
discr(Signed::Next, i128::MIN + 1);
|
||||
|
||||
discr(Unsigned::Zero, 0);
|
||||
discr(Unsigned::Staircase, 0x01_02_03_04_05_06_07_08_09_0a_0b_0c_0d_0e_0f);
|
||||
discr(Unsigned::U64Limit, u64::max_value() as u128 + 1);
|
||||
discr(Unsigned::Next, u64::max_value() as u128 + 2);
|
||||
discr(Unsigned::U64Limit, u64::MAX as u128 + 1);
|
||||
discr(Unsigned::Next, u64::MAX as u128 + 2);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,5 +6,5 @@ use std::time::{Instant, Duration};
|
|||
|
||||
fn main() {
|
||||
let now = Instant::now();
|
||||
let _ = now + Duration::from_secs(u64::max_value());
|
||||
let _ = now + Duration::from_secs(u64::MAX);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,5 +6,5 @@ use std::time::{Duration, SystemTime};
|
|||
|
||||
fn main() {
|
||||
let now = SystemTime::now();
|
||||
let _ = now + Duration::from_secs(u64::max_value());
|
||||
let _ = now + Duration::from_secs(u64::MAX);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,5 +6,5 @@ use std::time::{Instant, Duration};
|
|||
|
||||
fn main() {
|
||||
let now = Instant::now();
|
||||
let _ = now - Duration::from_secs(u64::max_value());
|
||||
let _ = now - Duration::from_secs(u64::MAX);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,5 +6,5 @@ use std::time::{Duration, SystemTime};
|
|||
|
||||
fn main() {
|
||||
let now = SystemTime::now();
|
||||
let _ = now - Duration::from_secs(u64::max_value());
|
||||
let _ = now - Duration::from_secs(u64::MAX);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,21 +27,21 @@ macro_rules! check {
|
|||
|
||||
fn main() {
|
||||
check![
|
||||
isize::min_value() / -isize::one(),
|
||||
i8::min_value() / -i8::one(),
|
||||
i16::min_value() / -i16::one(),
|
||||
i32::min_value() / -i32::one(),
|
||||
i64::min_value() / -i64::one(),
|
||||
isize::MIN / -isize::one(),
|
||||
i8::MIN / -i8::one(),
|
||||
i16::MIN / -i16::one(),
|
||||
i32::MIN / -i32::one(),
|
||||
i64::MIN / -i64::one(),
|
||||
1isize / isize::zero(),
|
||||
1i8 / i8::zero(),
|
||||
1i16 / i16::zero(),
|
||||
1i32 / i32::zero(),
|
||||
1i64 / i64::zero(),
|
||||
isize::min_value() % -isize::one(),
|
||||
i8::min_value() % -i8::one(),
|
||||
i16::min_value() % -i16::one(),
|
||||
i32::min_value() % -i32::one(),
|
||||
i64::min_value() % -i64::one(),
|
||||
isize::MIN % -isize::one(),
|
||||
i8::MIN % -i8::one(),
|
||||
i16::MIN % -i16::one(),
|
||||
i32::MIN % -i32::one(),
|
||||
i64::MIN % -i64::one(),
|
||||
1isize % isize::zero(),
|
||||
1i8 % i8::zero(),
|
||||
1i16 % i16::zero(),
|
||||
|
|
|
|||
|
|
@ -6,14 +6,14 @@ use std::panic;
|
|||
|
||||
fn main() {
|
||||
let r = panic::catch_unwind(|| {
|
||||
let mut it = u8::max_value()..;
|
||||
let mut it = u8::MAX..;
|
||||
it.next().unwrap(); // 255
|
||||
it.next().unwrap();
|
||||
});
|
||||
assert!(r.is_err());
|
||||
|
||||
let r = panic::catch_unwind(|| {
|
||||
let mut it = i8::max_value()..;
|
||||
let mut it = i8::MAX..;
|
||||
it.next().unwrap(); // 127
|
||||
it.next().unwrap();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@
|
|||
// compile-flags: -C debug_assertions=no
|
||||
|
||||
fn main() {
|
||||
let mut it = u8::max_value()..;
|
||||
let mut it = u8::MAX..;
|
||||
assert_eq!(it.next().unwrap(), 255);
|
||||
assert_eq!(it.next().unwrap(), u8::min_value());
|
||||
assert_eq!(it.next().unwrap(), u8::MIN);
|
||||
|
||||
let mut it = i8::max_value()..;
|
||||
let mut it = i8::MAX..;
|
||||
assert_eq!(it.next().unwrap(), 127);
|
||||
assert_eq!(it.next().unwrap(), i8::min_value());
|
||||
assert_eq!(it.next().unwrap(), i8::MIN);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,22 +6,22 @@ use std::panic;
|
|||
|
||||
fn main() {
|
||||
let r = panic::catch_unwind(|| {
|
||||
[1, i32::max_value()].iter().sum::<i32>();
|
||||
[1, i32::MAX].iter().sum::<i32>();
|
||||
});
|
||||
assert!(r.is_err());
|
||||
|
||||
let r = panic::catch_unwind(|| {
|
||||
[2, i32::max_value()].iter().product::<i32>();
|
||||
[2, i32::MAX].iter().product::<i32>();
|
||||
});
|
||||
assert!(r.is_err());
|
||||
|
||||
let r = panic::catch_unwind(|| {
|
||||
[1, i32::max_value()].iter().cloned().sum::<i32>();
|
||||
[1, i32::MAX].iter().cloned().sum::<i32>();
|
||||
});
|
||||
assert!(r.is_err());
|
||||
|
||||
let r = panic::catch_unwind(|| {
|
||||
[2, i32::max_value()].iter().cloned().product::<i32>();
|
||||
[2, i32::MAX].iter().cloned().product::<i32>();
|
||||
});
|
||||
assert!(r.is_err());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@
|
|||
// compile-flags: -C debug_assertions=no
|
||||
|
||||
fn main() {
|
||||
assert_eq!([1i32, i32::max_value()].iter().sum::<i32>(),
|
||||
1i32.wrapping_add(i32::max_value()));
|
||||
assert_eq!([2i32, i32::max_value()].iter().product::<i32>(),
|
||||
2i32.wrapping_mul(i32::max_value()));
|
||||
assert_eq!([1i32, i32::MAX].iter().sum::<i32>(),
|
||||
1i32.wrapping_add(i32::MAX));
|
||||
assert_eq!([2i32, i32::MAX].iter().product::<i32>(),
|
||||
2i32.wrapping_mul(i32::MAX));
|
||||
|
||||
assert_eq!([1i32, i32::max_value()].iter().cloned().sum::<i32>(),
|
||||
1i32.wrapping_add(i32::max_value()));
|
||||
assert_eq!([2i32, i32::max_value()].iter().cloned().product::<i32>(),
|
||||
2i32.wrapping_mul(i32::max_value()));
|
||||
assert_eq!([1i32, i32::MAX].iter().cloned().sum::<i32>(),
|
||||
1i32.wrapping_add(i32::MAX));
|
||||
assert_eq!([2i32, i32::MAX].iter().cloned().product::<i32>(),
|
||||
2i32.wrapping_mul(i32::MAX));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,22 +6,22 @@ use std::panic;
|
|||
|
||||
fn main() {
|
||||
let r = panic::catch_unwind(|| {
|
||||
[1, i32::max_value()].iter().sum::<i32>();
|
||||
[1, i32::MAX].iter().sum::<i32>();
|
||||
});
|
||||
assert!(r.is_err());
|
||||
|
||||
let r = panic::catch_unwind(|| {
|
||||
[2, i32::max_value()].iter().product::<i32>();
|
||||
[2, i32::MAX].iter().product::<i32>();
|
||||
});
|
||||
assert!(r.is_err());
|
||||
|
||||
let r = panic::catch_unwind(|| {
|
||||
[1, i32::max_value()].iter().cloned().sum::<i32>();
|
||||
[1, i32::MAX].iter().cloned().sum::<i32>();
|
||||
});
|
||||
assert!(r.is_err());
|
||||
|
||||
let r = panic::catch_unwind(|| {
|
||||
[2, i32::max_value()].iter().cloned().product::<i32>();
|
||||
[2, i32::MAX].iter().cloned().product::<i32>();
|
||||
});
|
||||
assert!(r.is_err());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,6 @@
|
|||
// compile-flags: -C overflow-checks -C opt-level=3
|
||||
|
||||
fn main() {
|
||||
let i = (0..usize::max_value()).chain(0..10).skip(usize::max_value());
|
||||
let i = (0..usize::MAX).chain(0..10).skip(usize::MAX);
|
||||
assert_eq!(i.count(), 10);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ fn main() {
|
|||
assert_eq!((-z).checked_mul(-z), Some(0x734C_C2F2_A521));
|
||||
assert_eq!((z).checked_mul(z), Some(0x734C_C2F2_A521));
|
||||
assert_eq!((k).checked_mul(k), None);
|
||||
let l: i128 = b(i128::min_value());
|
||||
let l: i128 = b(i128::MIN);
|
||||
let o: i128 = b(17);
|
||||
assert_eq!(l.checked_sub(b(2)), None);
|
||||
assert_eq!(l.checked_add(l), None);
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@
|
|||
use std::thread;
|
||||
|
||||
fn main() {
|
||||
assert!(thread::spawn(|| i8::min_value().abs()).join().is_err());
|
||||
assert!(thread::spawn(|| i16::min_value().abs()).join().is_err());
|
||||
assert!(thread::spawn(|| i32::min_value().abs()).join().is_err());
|
||||
assert!(thread::spawn(|| i64::min_value().abs()).join().is_err());
|
||||
assert!(thread::spawn(|| isize::min_value().abs()).join().is_err());
|
||||
assert!(thread::spawn(|| i8::MIN.abs()).join().is_err());
|
||||
assert!(thread::spawn(|| i16::MIN.abs()).join().is_err());
|
||||
assert!(thread::spawn(|| i32::MIN.abs()).join().is_err());
|
||||
assert!(thread::spawn(|| i64::MIN.abs()).join().is_err());
|
||||
assert!(thread::spawn(|| isize::MIN.abs()).join().is_err());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@ fn main() {
|
|||
macro_rules! overflow_test {
|
||||
($t:ident) => (
|
||||
let r = panic::catch_unwind(|| {
|
||||
($t::max_value()).next_power_of_two()
|
||||
($t::MAX).next_power_of_two()
|
||||
});
|
||||
assert!(r.is_err());
|
||||
|
||||
let r = panic::catch_unwind(|| {
|
||||
(($t::max_value() >> 1) + 2).next_power_of_two()
|
||||
(($t::MAX >> 1) + 2).next_power_of_two()
|
||||
});
|
||||
assert!(r.is_err());
|
||||
)
|
||||
|
|
|
|||
|
|
@ -5,5 +5,5 @@
|
|||
|
||||
fn main() {
|
||||
let x = &(0u32 - 1);
|
||||
assert_eq!(*x, u32::max_value())
|
||||
assert_eq!(*x, u32::MAX)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,14 +53,14 @@ fn main() {
|
|||
assert_eq!("10000000000000000000000000000000000000000000000000000000000000000000",
|
||||
format!("{:b}", j));
|
||||
assert_eq!("340282366920938463463374607431768211455",
|
||||
format!("{}", u128::max_value()));
|
||||
format!("{}", u128::MAX));
|
||||
assert_eq!("147573952589676412928", format!("{:?}", j));
|
||||
// common traits
|
||||
assert_eq!(x, b(x.clone()));
|
||||
// overflow checks
|
||||
assert_eq!((z).checked_mul(z), Some(0x734C_C2F2_A521));
|
||||
assert_eq!((k).checked_mul(k), None);
|
||||
let l: u128 = b(u128::max_value() - 10);
|
||||
let l: u128 = b(u128::MAX - 10);
|
||||
let o: u128 = b(17);
|
||||
assert_eq!(l.checked_add(b(11)), None);
|
||||
assert_eq!(l.checked_sub(l), Some(0));
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ extern "platform-intrinsic" {
|
|||
fn main() {
|
||||
// unsigned
|
||||
{
|
||||
const M: u32 = u32::max_value();
|
||||
const M: u32 = u32::MAX;
|
||||
|
||||
let a = u32x4(1, 2, 3, 4);
|
||||
let b = u32x4(2, 4, 6, 8);
|
||||
|
|
@ -48,8 +48,8 @@ fn main() {
|
|||
|
||||
// signed
|
||||
{
|
||||
const MIN: i32 = i32::min_value();
|
||||
const MAX: i32 = i32::max_value();
|
||||
const MIN: i32 = i32::MIN;
|
||||
const MAX: i32 = i32::MAX;
|
||||
|
||||
let a = i32x4(1, 2, 3, 4);
|
||||
let b = i32x4(2, 4, 6, 8);
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ fn main() {
|
|||
let e = 0b_1101;
|
||||
|
||||
// Check usize / isize
|
||||
let msize: Tx4<usize> = Tx4(usize::max_value(), 0, usize::max_value(), usize::max_value());
|
||||
let msize: Tx4<usize> = Tx4(usize::MAX, 0, usize::MAX, usize::MAX);
|
||||
|
||||
unsafe {
|
||||
let r: u8 = simd_bitmask(z);
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ fn main() {
|
|||
let r: u32 = simd_reduce_max(x);
|
||||
assert_eq!(r, 4_u32);
|
||||
|
||||
let t = u32::max_value();
|
||||
let t = u32::MAX;
|
||||
let x = u32x4(t, t, t, t);
|
||||
let r: u32 = simd_reduce_and(x);
|
||||
assert_eq!(r, t);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue