This commit is contained in:
Dylan MacKenzie 2020-02-04 11:46:13 -08:00
parent 09160d1b84
commit 040d9873aa

View File

@ -1,166 +1,130 @@
// run-pass // run-pass
#![feature(const_int_checked)] #![feature(saturating_neg)]
#![feature(const_int_euclidean)] #![feature(const_checked_int_methods)]
#![feature(const_int_overflowing)] #![feature(const_euclidean_int_methods)]
#![feature(const_int_saturating)] #![feature(const_overflowing_int_methods)]
#![feature(const_int_wrapping)] #![feature(const_saturating_int_methods)]
#![feature(const_wrapping_int_methods)]
macro_rules! assert_same_const { use std::i8;
($(const $ident:ident: $ty:ty = $exp:expr;)+) => {
$(const $ident: $ty = $exp;)+
pub fn main() { macro_rules! suite {
$(assert_eq!($exp, $ident);)+ ($(
} $fn:ident -> $ty:ty { $( $label:ident : $expr:expr, $result:expr; )* }
)*) => { $(
fn $fn() {
$(
const $label: $ty = $expr;
assert_eq!($label, $result);
)*
} }
)* }
} }
assert_same_const! { suite!(
// `const_int_checked` checked -> Option<i8> {
const CHECKED_ADD_I32_A: Option<i32> = 5i32.checked_add(2); // `const_checked_int_methods`
const CHECKED_ADD_I8_A: Option<i8> = 127i8.checked_add(2); C1: 5i8.checked_add(2), Some(7);
const CHECKED_ADD_U8_A: Option<u8> = 255u8.checked_add(2); C2: 127i8.checked_add(2), None;
const CHECKED_SUB_I32_A: Option<i32> = 5i32.checked_sub(2); C3: 5i8.checked_sub(2), Some(3);
const CHECKED_SUB_I8_A: Option<i8> = (-127 as i8).checked_sub(2); C4: (-127i8).checked_sub(2), None;
const CHECKED_SUB_U8_A: Option<u8> = 1u8.checked_sub(2);
const CHECKED_MUL_I32_A: Option<i32> = 5i32.checked_mul(7777); C5: 1i8.checked_mul(3), Some(3);
const CHECKED_MUL_I8_A: Option<i8> = (-127 as i8).checked_mul(-99); C6: 5i8.checked_mul(122), None;
const CHECKED_MUL_U8_A: Option<u8> = 1u8.checked_mul(3); C7: (-127i8).checked_mul(-99), None;
const CHECKED_DIV_I32_A: Option<i32> = 5i32.checked_div(7777); C8: (i8::min_value() + 1).checked_div(-1), Some(127);
const CHECKED_DIV_I8_A: Option<i8> = (-127 as i8).checked_div(-99); C9: i8::min_value().checked_div(-1), None;
const CHECKED_DIV_U8_A: Option<u8> = 1u8.checked_div(3); C10: 1i8.checked_div(0), None;
const CHECKED_REM_I32_A: Option<i32> = 5i32.checked_rem(7777); C11: 5i8.checked_rem(2), Some(1);
const CHECKED_REM_I8_A: Option<i8> = (-127 as i8).checked_rem(-99); C12: 5i8.checked_rem(0), None;
const CHECKED_REM_U8_A: Option<u8> = 1u8.checked_rem(3); C13: i8::MIN.checked_rem(-1), None;
const CHECKED_REM_U8_B: Option<u8> = 1u8.checked_rem(0);
const CHECKED_NEG_I32_A: Option<i32> = 5i32.checked_neg(); C14: 5i8.checked_neg(), Some(-5);
const CHECKED_NEG_I8_A: Option<i8> = (-127 as i8).checked_neg(); C15: i8::MIN.checked_neg(), None;
const CHECKED_NEG_U8_A: Option<u8> = 1u8.checked_neg();
const CHECKED_NEG_U8_B: Option<u8> = u8::min_value().checked_neg();
const CHECKED_SHL_I32_A: Option<i32> = 5i32.checked_shl(77777); C16: 0x1i8.checked_shl(4), Some(0x10);
const CHECKED_SHL_I8_A: Option<i8> = (-127 as i8).checked_shl(2); C17: 0x1i8.checked_shl(129), None;
const CHECKED_SHL_U8_A: Option<u8> = 1u8.checked_shl(8);
const CHECKED_SHL_U8_B: Option<u8> = 1u8.checked_shl(0);
const CHECKED_SHR_I32_A: Option<i32> = 5i32.checked_shr(77777); C18: 0x10i8.checked_shr(4), Some(0x1);
const CHECKED_SHR_I8_A: Option<i8> = (-127 as i8).checked_shr(2); C19: 0x10i8.checked_shr(128), None;
const CHECKED_SHR_U8_A: Option<u8> = 1u8.checked_shr(8);
const CHECKED_SHR_U8_B: Option<u8> = 1u8.checked_shr(0);
const CHECKED_ABS_I32_A: Option<i32> = 5i32.checked_abs();
const CHECKED_ABS_I8_A: Option<i8> = (-127 as i8).checked_abs();
const CHECKED_ABS_I8_B: Option<i8> = 1i8.checked_abs();
const CHECKED_ABS_I8_C: Option<i8> = i8::min_value().checked_abs();
// `const_int_overflowing` C20: (-5i8).checked_abs(), Some(5);
const DIV_A: (i8, bool) = 8i8.overflowing_div(2); C21: i8::MIN.checked_abs(), None;
const DIV_B: (i8, bool) = 8i8.overflowing_div(3);
const DIV_C: (i8, bool) = i8::min_value().overflowing_div(-1i8);
const DIV_D: (u8, bool) = 8u8.overflowing_div(2);
const DIV_E: (u8, bool) = 8u8.overflowing_div(3);
const REM_A: (i8, bool) = 8i8.overflowing_rem(2); // `const_euclidean_int_methods`
const REM_B: (i8, bool) = 8i8.overflowing_rem(3); C22: (i8::min_value() + 1).checked_div_euclid(-1), Some(127);
const REM_C: (i8, bool) = i8::min_value().overflowing_rem(-1i8); C23: i8::min_value().checked_div_euclid(-1), None;
const REM_D: (u8, bool) = 8u8.overflowing_rem(2); C24: (1i8).checked_div_euclid(0), None;
const REM_E: (u8, bool) = 8u8.overflowing_rem(3);
// `const_int_saturating` C25: 5i8.checked_rem_euclid(2), Some(1);
const ADD_INT_U32_NO: u32 = (42 as u32).saturating_add(2); C26: 5i8.checked_rem_euclid(0), None;
const ADD_INT_U32: u32 = u32::max_value().saturating_add(1); C27: i8::MIN.checked_rem_euclid(-1), None;
const ADD_INT_U128: u128 = u128::max_value().saturating_add(1); }
const ADD_INT_I128: i128 = i128::max_value().saturating_add(1);
const ADD_INT_I128_NEG: i128 = i128::min_value().saturating_add(-1);
const SUB_INT_U32_NO: u32 = (42 as u32).saturating_sub(2); saturating_and_wrapping -> i8 {
const SUB_INT_U32: u32 = (1 as u32).saturating_sub(2); // `const_saturating_int_methods`
const SUB_INT_I32_NO: i32 = (-42 as i32).saturating_sub(2); C28: 100i8.saturating_add(1), 101;
const SUB_INT_I32_NEG: i32 = i32::min_value().saturating_sub(1); C29: i8::max_value().saturating_add(100), i8::max_value();
const SUB_INT_I32_POS: i32 = i32::max_value().saturating_sub(-1); C30: i8::min_value().saturating_add(-1), i8::min_value();
const SUB_INT_U128: u128 = (0 as u128).saturating_sub(1);
const SUB_INT_I128_NEG: i128 = i128::min_value().saturating_sub(1);
const SUB_INT_I128_POS: i128 = i128::max_value().saturating_sub(-1);
const MUL_INT_U32_NO: u32 = (42 as u32).saturating_mul(2); C31: 100i8.saturating_sub(127), -27;
const MUL_INT_U32: u32 = (1 as u32).saturating_mul(2); C32: i8::min_value().saturating_sub(100), i8::min_value();
const MUL_INT_I32_NO: i32 = (-42 as i32).saturating_mul(2); C33: i8::max_value().saturating_sub(-1), i8::max_value();
const MUL_INT_I32_NEG: i32 = i32::min_value().saturating_mul(1);
const MUL_INT_I32_POS: i32 = i32::max_value().saturating_mul(2);
const MUL_INT_U128: u128 = (0 as u128).saturating_mul(1);
const MUL_INT_I128_NEG: i128 = i128::min_value().saturating_mul(2);
const MUL_INT_I128_POS: i128 = i128::max_value().saturating_mul(2);
const NEG_INT_I8: i8 = (-42i8).saturating_neg(); C34: 10i8.saturating_mul(12), 120;
const NEG_INT_I8_B: i8 = i8::min_value().saturating_neg(); C35: i8::MAX.saturating_mul(10), i8::MAX;
const NEG_INT_I32: i32 = i32::min_value().saturating_neg(); C36: i8::MIN.saturating_mul(10), i8::MIN;
const NEG_INT_I32_B: i32 = i32::max_value().saturating_neg();
const NEG_INT_I128: i128 = i128::min_value().saturating_neg();
const NEG_INT_I128_B: i128 = i128::max_value().saturating_neg();
const ABS_INT_I8_A: i8 = 4i8.saturating_abs(); C37: 100i8.saturating_neg(), -100;
const ABS_INT_I8_B: i8 = -4i8.saturating_abs(); C38: (-100i8).saturating_neg(), 100;
const ABS_INT_I8_C: i8 = i8::min_value().saturating_abs(); C39: i8::min_value().saturating_neg(), i8::max_value();
const ABS_INT_I32_A: i32 = 4i32.saturating_abs(); C40: i8::max_value().saturating_neg(), i8::min_value() + 1;
const ABS_INT_I32_B: i32 = -4i32.saturating_abs();
const ABS_INT_I32_C: i32 = i32::min_value().saturating_abs();
const ABS_INT_I128_A: i128 = 4i128.saturating_abs();
const ABS_INT_I128_B: i128 = -4i128.saturating_abs();
const ABS_INT_I128_C: i128 = i128::min_value().saturating_abs();
// `const_int_euclidean` C57: 100i8.saturating_abs(), 100;
const CHECKED_DIV_I32_A: Option<i32> = 5i32.checked_div_euclid(7777); C58: (-100i8).saturating_abs(), 100;
const CHECKED_DIV_I8_A: Option<i8> = (-127 as i8).checked_div_euclid(-99); C59: i8::min_value().saturating_abs(), i8::max_value();
const CHECKED_DIV_I8_B: Option<i8> = (-127 as i8).checked_div_euclid(1); C60: (i8::min_value() + 1).saturating_abs(), i8::max_value();
const CHECKED_DIV_I8_C: Option<i8> = i8::min_value().checked_div_euclid(-1);
const CHECKED_DIV_U8_A: Option<u8> = 1u8.checked_div_euclid(3);
const CHECKED_REM_I32_A: Option<i32> = 5i32.checked_rem_euclid(7777); // `const_wrapping_int_methods`
const CHECKED_REM_I8_A: Option<i8> = (-127 as i8).checked_rem_euclid(-99); C41: 100i8.wrapping_div(10), 10;
const CHECKED_REM_I8_B: Option<i8> = (-127 as i8).checked_rem_euclid(0); C42: (-128i8).wrapping_div(-1), -128;
const CHECKED_REM_I8_C: Option<i8> = i8::min_value().checked_rem_euclid(-1);
const CHECKED_REM_U8_A: Option<u8> = 1u8.checked_rem_euclid(3);
const WRAPPING_DIV_I32_A: i32 = 5i32.wrapping_div_euclid(7777); C43: 100i8.wrapping_rem(10), 0;
const WRAPPING_DIV_I8_A: i8 = (-127 as i8).wrapping_div_euclid(-99); C44: (-128i8).wrapping_rem(-1), 0;
const WRAPPING_DIV_I8_B: i8 = (-127 as i8).wrapping_div_euclid(1);
const WRAPPING_DIV_I8_C: i8 = i8::min_value().wrapping_div_euclid(-1);
const WRAPPING_DIV_U8_A: u8 = 1u8.wrapping_div_euclid(3);
const WRAPPING_REM_I32_A: i32 = 5i32.wrapping_rem_euclid(7777); // `const_euclidean_int_methods`
const WRAPPING_REM_I8_A: i8 = (-127 as i8).wrapping_rem_euclid(-99); C45: 100i8.wrapping_div_euclid(10), 10;
const WRAPPING_REM_I8_B: i8 = (-127 as i8).wrapping_rem_euclid(1); C46: (-128i8).wrapping_div_euclid(-1), -128;
const WRAPPING_REM_I8_C: i8 = i8::min_value().wrapping_rem_euclid(-1);
const WRAPPING_REM_U8_A: u8 = 1u8.wrapping_rem_euclid(3);
const OVERFLOWING_DIV_I32_A: (i32, bool) = 5i32.overflowing_div_euclid(7777); C47: 100i8.wrapping_rem_euclid(10), 0;
const OVERFLOWING_DIV_I8_A: (i8, bool) = (-127 as i8).overflowing_div_euclid(-99); C48: (-128i8).wrapping_rem_euclid(-1), 0;
const OVERFLOWING_DIV_I8_B: (i8, bool) = (-127 as i8).overflowing_div_euclid(1); }
const OVERFLOWING_DIV_I8_C: (i8, bool) = i8::min_value().overflowing_div_euclid(-1);
const OVERFLOWING_DIV_U8_A: (u8, bool) = 1u8.overflowing_div_euclid(3);
const OVERFLOWING_REM_I32_A: (i32, bool) = 5i32.overflowing_rem_euclid(7777); overflowing -> (i8, bool) {
const OVERFLOWING_REM_I8_A: (i8, bool) = (-127 as i8).overflowing_rem_euclid(-99); // `const_overflowing_int_methods`
const OVERFLOWING_REM_I8_B: (i8, bool) = (-127 as i8).overflowing_rem_euclid(1); C49: 5i8.overflowing_div(2), (2, false);
const OVERFLOWING_REM_I8_C: (i8, bool) = i8::min_value().overflowing_rem_euclid(-1); C50: i8::MIN.overflowing_div(-1), (i8::MIN, true);
const OVERFLOWING_REM_U8_A: (u8, bool) = 1u8.overflowing_rem_euclid(3);
// `const_int_wrapping` C51: 5i8.overflowing_rem(2), (1, false);
const DIV_A: i8 = 8i8.wrapping_div(2); C52: i8::MIN.overflowing_rem(-1), (0, true);
const DIV_B: i8 = 8i8.wrapping_div(3);
const DIV_C: i8 = i8::min_value().wrapping_div(-1i8);
const DIV_D: u8 = 8u8.wrapping_div(2);
const DIV_E: u8 = 8u8.wrapping_div(3);
const REM_A: i8 = 8i8.wrapping_rem(2); // `const_euclidean_int_methods`
const REM_B: i8 = 8i8.wrapping_rem(3); C53: 5i8.overflowing_div_euclid(2), (2, false);
const REM_C: i8 = i8::min_value().wrapping_rem(-1i8); C54: i8::MIN.overflowing_div_euclid(-1), (i8::MIN, true);
const REM_D: u8 = 8u8.wrapping_rem(2);
const REM_E: u8 = 8u8.wrapping_rem(3); C55: 5i8.overflowing_rem_euclid(2), (1, false);
C56: i8::MIN.overflowing_rem_euclid(-1), (0, true);
}
);
fn main() {
checked();
saturating_and_wrapping();
overflowing();
} }