Rollup merge of #147771 - nxsaken:div_shlr_exact, r=dtolnay

Rename `*exact_{div,shr,shl}` to `*{div,shr,shl}_exact`

Related to rust-lang/rust#144336 and rust-lang/rust#139911, see https://github.com/rust-lang/rust/issues/139911#issuecomment-3406807537. I haven't touched the `exact_div`, `exact_udiv` and `exact_sdiv` intrinsics. Let me know if I should.
This commit is contained in:
Stuart Cook
2025-11-11 21:09:34 +11:00
committed by GitHub
4 changed files with 93 additions and 93 deletions
+30 -30
View File
@@ -992,10 +992,10 @@ pub const fn strict_div_euclid(self, rhs: Self) -> Self {
///
/// ```
/// #![feature(exact_div)]
#[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN + 1).checked_exact_div(-1), Some(", stringify!($Max), "));")]
#[doc = concat!("assert_eq!((-5", stringify!($SelfT), ").checked_exact_div(2), None);")]
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.checked_exact_div(-1), None);")]
#[doc = concat!("assert_eq!((1", stringify!($SelfT), ").checked_exact_div(0), None);")]
#[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN + 1).checked_div_exact(-1), Some(", stringify!($Max), "));")]
#[doc = concat!("assert_eq!((-5", stringify!($SelfT), ").checked_div_exact(2), None);")]
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.checked_div_exact(-1), None);")]
#[doc = concat!("assert_eq!((1", stringify!($SelfT), ").checked_div_exact(0), None);")]
/// ```
#[unstable(
feature = "exact_div",
@@ -1004,7 +1004,7 @@ pub const fn strict_div_euclid(self, rhs: Self) -> Self {
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub const fn checked_exact_div(self, rhs: Self) -> Option<Self> {
pub const fn checked_div_exact(self, rhs: Self) -> Option<Self> {
if intrinsics::unlikely(rhs == 0 || ((self == Self::MIN) && (rhs == -1))) {
None
} else {
@@ -1034,18 +1034,18 @@ pub const fn checked_exact_div(self, rhs: Self) -> Option<Self> {
///
/// ```
/// #![feature(exact_div)]
#[doc = concat!("assert_eq!(64", stringify!($SelfT), ".exact_div(2), Some(32));")]
#[doc = concat!("assert_eq!(64", stringify!($SelfT), ".exact_div(32), Some(2));")]
#[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN + 1).exact_div(-1), Some(", stringify!($Max), "));")]
#[doc = concat!("assert_eq!(65", stringify!($SelfT), ".exact_div(2), None);")]
#[doc = concat!("assert_eq!(64", stringify!($SelfT), ".div_exact(2), Some(32));")]
#[doc = concat!("assert_eq!(64", stringify!($SelfT), ".div_exact(32), Some(2));")]
#[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN + 1).div_exact(-1), Some(", stringify!($Max), "));")]
#[doc = concat!("assert_eq!(65", stringify!($SelfT), ".div_exact(2), None);")]
/// ```
/// ```should_panic
/// #![feature(exact_div)]
#[doc = concat!("let _ = 64", stringify!($SelfT),".exact_div(0);")]
#[doc = concat!("let _ = 64", stringify!($SelfT),".div_exact(0);")]
/// ```
/// ```should_panic
/// #![feature(exact_div)]
#[doc = concat!("let _ = ", stringify!($SelfT), "::MIN.exact_div(-1);")]
#[doc = concat!("let _ = ", stringify!($SelfT), "::MIN.div_exact(-1);")]
/// ```
#[unstable(
feature = "exact_div",
@@ -1055,7 +1055,7 @@ pub const fn checked_exact_div(self, rhs: Self) -> Option<Self> {
without modifying the original"]
#[inline]
#[rustc_inherit_overflow_checks]
pub const fn exact_div(self, rhs: Self) -> Option<Self> {
pub const fn div_exact(self, rhs: Self) -> Option<Self> {
if self % rhs != 0 {
None
} else {
@@ -1069,7 +1069,7 @@ pub const fn exact_div(self, rhs: Self) -> Option<Self> {
///
/// This results in undefined behavior when `rhs == 0`, `self % rhs != 0`, or
#[doc = concat!("`self == ", stringify!($SelfT), "::MIN && rhs == -1`,")]
/// i.e. when [`checked_exact_div`](Self::checked_exact_div) would return `None`.
/// i.e. when [`checked_div_exact`](Self::checked_div_exact) would return `None`.
#[unstable(
feature = "exact_div",
issue = "139911",
@@ -1077,10 +1077,10 @@ pub const fn exact_div(self, rhs: Self) -> Option<Self> {
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub const unsafe fn unchecked_exact_div(self, rhs: Self) -> Self {
pub const unsafe fn unchecked_div_exact(self, rhs: Self) -> Self {
assert_unsafe_precondition!(
check_language_ub,
concat!(stringify!($SelfT), "::unchecked_exact_div cannot overflow, divide by zero, or leave a remainder"),
concat!(stringify!($SelfT), "::unchecked_div_exact cannot overflow, divide by zero, or leave a remainder"),
(
lhs: $SelfT = self,
rhs: $SelfT = rhs,
@@ -1431,17 +1431,17 @@ pub const fn unbounded_shl(self, rhs: u32) -> $SelfT{
/// ```
/// #![feature(exact_bitshifts)]
///
#[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".exact_shl(4), Some(0x10));")]
#[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".exact_shl(", stringify!($SelfT), "::BITS - 2), Some(1 << ", stringify!($SelfT), "::BITS - 2));")]
#[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".exact_shl(", stringify!($SelfT), "::BITS - 1), None);")]
#[doc = concat!("assert_eq!((-0x2", stringify!($SelfT), ").exact_shl(", stringify!($SelfT), "::BITS - 2), Some(-0x2 << ", stringify!($SelfT), "::BITS - 2));")]
#[doc = concat!("assert_eq!((-0x2", stringify!($SelfT), ").exact_shl(", stringify!($SelfT), "::BITS - 1), None);")]
#[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".shl_exact(4), Some(0x10));")]
#[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".shl_exact(", stringify!($SelfT), "::BITS - 2), Some(1 << ", stringify!($SelfT), "::BITS - 2));")]
#[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".shl_exact(", stringify!($SelfT), "::BITS - 1), None);")]
#[doc = concat!("assert_eq!((-0x2", stringify!($SelfT), ").shl_exact(", stringify!($SelfT), "::BITS - 2), Some(-0x2 << ", stringify!($SelfT), "::BITS - 2));")]
#[doc = concat!("assert_eq!((-0x2", stringify!($SelfT), ").shl_exact(", stringify!($SelfT), "::BITS - 1), None);")]
/// ```
#[unstable(feature = "exact_bitshifts", issue = "144336")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub const fn exact_shl(self, rhs: u32) -> Option<$SelfT> {
pub const fn shl_exact(self, rhs: u32) -> Option<$SelfT> {
if rhs < self.leading_zeros() || rhs < self.leading_ones() {
// SAFETY: rhs is checked above
Some(unsafe { self.unchecked_shl(rhs) })
@@ -1458,16 +1458,16 @@ pub const fn exact_shl(self, rhs: u32) -> Option<$SelfT> {
///
/// This results in undefined behavior when `rhs >= self.leading_zeros() && rhs >=
/// self.leading_ones()` i.e. when
#[doc = concat!("[`", stringify!($SelfT), "::exact_shl`]")]
#[doc = concat!("[`", stringify!($SelfT), "::shl_exact`]")]
/// would return `None`.
#[unstable(feature = "exact_bitshifts", issue = "144336")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub const unsafe fn unchecked_exact_shl(self, rhs: u32) -> $SelfT {
pub const unsafe fn unchecked_shl_exact(self, rhs: u32) -> $SelfT {
assert_unsafe_precondition!(
check_library_ub,
concat!(stringify!($SelfT), "::unchecked_exact_shl cannot shift out bits that would change the value of the first bit"),
concat!(stringify!($SelfT), "::unchecked_shl_exact cannot shift out bits that would change the value of the first bit"),
(
zeros: u32 = self.leading_zeros(),
ones: u32 = self.leading_ones(),
@@ -1611,14 +1611,14 @@ pub const fn unbounded_shr(self, rhs: u32) -> $SelfT{
/// ```
/// #![feature(exact_bitshifts)]
///
#[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".exact_shr(4), Some(0x1));")]
#[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".exact_shr(5), None);")]
#[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".shr_exact(4), Some(0x1));")]
#[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".shr_exact(5), None);")]
/// ```
#[unstable(feature = "exact_bitshifts", issue = "144336")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub const fn exact_shr(self, rhs: u32) -> Option<$SelfT> {
pub const fn shr_exact(self, rhs: u32) -> Option<$SelfT> {
if rhs <= self.trailing_zeros() && rhs < <$SelfT>::BITS {
// SAFETY: rhs is checked above
Some(unsafe { self.unchecked_shr(rhs) })
@@ -1636,16 +1636,16 @@ pub const fn exact_shr(self, rhs: u32) -> Option<$SelfT> {
/// This results in undefined behavior when `rhs > self.trailing_zeros() || rhs >=
#[doc = concat!(stringify!($SelfT), "::BITS`")]
/// i.e. when
#[doc = concat!("[`", stringify!($SelfT), "::exact_shr`]")]
#[doc = concat!("[`", stringify!($SelfT), "::shr_exact`]")]
/// would return `None`.
#[unstable(feature = "exact_bitshifts", issue = "144336")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub const unsafe fn unchecked_exact_shr(self, rhs: u32) -> $SelfT {
pub const unsafe fn unchecked_shr_exact(self, rhs: u32) -> $SelfT {
assert_unsafe_precondition!(
check_library_ub,
concat!(stringify!($SelfT), "::unchecked_exact_shr cannot shift out non-zero bits"),
concat!(stringify!($SelfT), "::unchecked_shr_exact cannot shift out non-zero bits"),
(
zeros: u32 = self.trailing_zeros(),
bits: u32 = <$SelfT>::BITS,
+24 -24
View File
@@ -1222,10 +1222,10 @@ pub const fn strict_div_euclid(self, rhs: Self) -> Self {
///
/// ```
/// #![feature(exact_div)]
#[doc = concat!("assert_eq!(64", stringify!($SelfT), ".checked_exact_div(2), Some(32));")]
#[doc = concat!("assert_eq!(64", stringify!($SelfT), ".checked_exact_div(32), Some(2));")]
#[doc = concat!("assert_eq!(64", stringify!($SelfT), ".checked_exact_div(0), None);")]
#[doc = concat!("assert_eq!(65", stringify!($SelfT), ".checked_exact_div(2), None);")]
#[doc = concat!("assert_eq!(64", stringify!($SelfT), ".checked_div_exact(2), Some(32));")]
#[doc = concat!("assert_eq!(64", stringify!($SelfT), ".checked_div_exact(32), Some(2));")]
#[doc = concat!("assert_eq!(64", stringify!($SelfT), ".checked_div_exact(0), None);")]
#[doc = concat!("assert_eq!(65", stringify!($SelfT), ".checked_div_exact(2), None);")]
/// ```
#[unstable(
feature = "exact_div",
@@ -1234,7 +1234,7 @@ pub const fn strict_div_euclid(self, rhs: Self) -> Self {
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub const fn checked_exact_div(self, rhs: Self) -> Option<Self> {
pub const fn checked_div_exact(self, rhs: Self) -> Option<Self> {
if intrinsics::unlikely(rhs == 0) {
None
} else {
@@ -1259,9 +1259,9 @@ pub const fn checked_exact_div(self, rhs: Self) -> Option<Self> {
///
/// ```
/// #![feature(exact_div)]
#[doc = concat!("assert_eq!(64", stringify!($SelfT), ".exact_div(2), Some(32));")]
#[doc = concat!("assert_eq!(64", stringify!($SelfT), ".exact_div(32), Some(2));")]
#[doc = concat!("assert_eq!(65", stringify!($SelfT), ".exact_div(2), None);")]
#[doc = concat!("assert_eq!(64", stringify!($SelfT), ".div_exact(2), Some(32));")]
#[doc = concat!("assert_eq!(64", stringify!($SelfT), ".div_exact(32), Some(2));")]
#[doc = concat!("assert_eq!(65", stringify!($SelfT), ".div_exact(2), None);")]
/// ```
#[unstable(
feature = "exact_div",
@@ -1271,7 +1271,7 @@ pub const fn checked_exact_div(self, rhs: Self) -> Option<Self> {
without modifying the original"]
#[inline]
#[rustc_inherit_overflow_checks]
pub const fn exact_div(self, rhs: Self) -> Option<Self> {
pub const fn div_exact(self, rhs: Self) -> Option<Self> {
if self % rhs != 0 {
None
} else {
@@ -1284,7 +1284,7 @@ pub const fn exact_div(self, rhs: Self) -> Option<Self> {
/// # Safety
///
/// This results in undefined behavior when `rhs == 0` or `self % rhs != 0`,
/// i.e. when [`checked_exact_div`](Self::checked_exact_div) would return `None`.
/// i.e. when [`checked_div_exact`](Self::checked_div_exact) would return `None`.
#[unstable(
feature = "exact_div",
issue = "139911",
@@ -1292,10 +1292,10 @@ pub const fn exact_div(self, rhs: Self) -> Option<Self> {
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub const unsafe fn unchecked_exact_div(self, rhs: Self) -> Self {
pub const unsafe fn unchecked_div_exact(self, rhs: Self) -> Self {
assert_unsafe_precondition!(
check_language_ub,
concat!(stringify!($SelfT), "::unchecked_exact_div divide by zero or leave a remainder"),
concat!(stringify!($SelfT), "::unchecked_div_exact divide by zero or leave a remainder"),
(
lhs: $SelfT = self,
rhs: $SelfT = rhs,
@@ -1830,14 +1830,14 @@ pub const fn unbounded_shl(self, rhs: u32) -> $SelfT{
/// ```
/// #![feature(exact_bitshifts)]
///
#[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".exact_shl(4), Some(0x10));")]
#[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".exact_shl(129), None);")]
#[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".shl_exact(4), Some(0x10));")]
#[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".shl_exact(129), None);")]
/// ```
#[unstable(feature = "exact_bitshifts", issue = "144336")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub const fn exact_shl(self, rhs: u32) -> Option<$SelfT> {
pub const fn shl_exact(self, rhs: u32) -> Option<$SelfT> {
if rhs <= self.leading_zeros() && rhs < <$SelfT>::BITS {
// SAFETY: rhs is checked above
Some(unsafe { self.unchecked_shl(rhs) })
@@ -1855,16 +1855,16 @@ pub const fn exact_shl(self, rhs: u32) -> Option<$SelfT> {
/// This results in undefined behavior when `rhs > self.leading_zeros() || rhs >=
#[doc = concat!(stringify!($SelfT), "::BITS`")]
/// i.e. when
#[doc = concat!("[`", stringify!($SelfT), "::exact_shl`]")]
#[doc = concat!("[`", stringify!($SelfT), "::shl_exact`]")]
/// would return `None`.
#[unstable(feature = "exact_bitshifts", issue = "144336")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub const unsafe fn unchecked_exact_shl(self, rhs: u32) -> $SelfT {
pub const unsafe fn unchecked_shl_exact(self, rhs: u32) -> $SelfT {
assert_unsafe_precondition!(
check_library_ub,
concat!(stringify!($SelfT), "::exact_shl_unchecked cannot shift out non-zero bits"),
concat!(stringify!($SelfT), "::unchecked_shl_exact cannot shift out non-zero bits"),
(
zeros: u32 = self.leading_zeros(),
bits: u32 = <$SelfT>::BITS,
@@ -2002,14 +2002,14 @@ pub const fn unbounded_shr(self, rhs: u32) -> $SelfT{
/// ```
/// #![feature(exact_bitshifts)]
///
#[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".exact_shr(4), Some(0x1));")]
#[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".exact_shr(5), None);")]
#[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".shr_exact(4), Some(0x1));")]
#[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".shr_exact(5), None);")]
/// ```
#[unstable(feature = "exact_bitshifts", issue = "144336")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub const fn exact_shr(self, rhs: u32) -> Option<$SelfT> {
pub const fn shr_exact(self, rhs: u32) -> Option<$SelfT> {
if rhs <= self.trailing_zeros() && rhs < <$SelfT>::BITS {
// SAFETY: rhs is checked above
Some(unsafe { self.unchecked_shr(rhs) })
@@ -2027,16 +2027,16 @@ pub const fn exact_shr(self, rhs: u32) -> Option<$SelfT> {
/// This results in undefined behavior when `rhs > self.trailing_zeros() || rhs >=
#[doc = concat!(stringify!($SelfT), "::BITS`")]
/// i.e. when
#[doc = concat!("[`", stringify!($SelfT), "::exact_shr`]")]
#[doc = concat!("[`", stringify!($SelfT), "::shr_exact`]")]
/// would return `None`.
#[unstable(feature = "exact_bitshifts", issue = "144336")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub const unsafe fn unchecked_exact_shr(self, rhs: u32) -> $SelfT {
pub const unsafe fn unchecked_shr_exact(self, rhs: u32) -> $SelfT {
assert_unsafe_precondition!(
check_library_ub,
concat!(stringify!($SelfT), "::exact_shr_unchecked cannot shift out non-zero bits"),
concat!(stringify!($SelfT), "::unchecked_shr_exact cannot shift out non-zero bits"),
(
zeros: u32 = self.trailing_zeros(),
bits: u32 = <$SelfT>::BITS,
+25 -25
View File
@@ -724,42 +724,42 @@ fn test_unbounded_shr() {
}
}
const EXACT_DIV_SUCCESS_DIVIDEND1: $T = 42;
const EXACT_DIV_SUCCESS_DIVISOR1: $T = 6;
const EXACT_DIV_SUCCESS_QUOTIENT1: $T = 7;
const EXACT_DIV_SUCCESS_DIVIDEND2: $T = 18;
const EXACT_DIV_SUCCESS_DIVISOR2: $T = 3;
const EXACT_DIV_SUCCESS_QUOTIENT2: $T = 6;
const EXACT_DIV_SUCCESS_DIVIDEND3: $T = -91;
const EXACT_DIV_SUCCESS_DIVISOR3: $T = 13;
const EXACT_DIV_SUCCESS_QUOTIENT3: $T = -7;
const EXACT_DIV_SUCCESS_DIVIDEND4: $T = -57;
const EXACT_DIV_SUCCESS_DIVISOR4: $T = -3;
const EXACT_DIV_SUCCESS_QUOTIENT4: $T = 19;
const DIV_EXACT_SUCCESS_DIVIDEND1: $T = 42;
const DIV_EXACT_SUCCESS_DIVISOR1: $T = 6;
const DIV_EXACT_SUCCESS_QUOTIENT1: $T = 7;
const DIV_EXACT_SUCCESS_DIVIDEND2: $T = 18;
const DIV_EXACT_SUCCESS_DIVISOR2: $T = 3;
const DIV_EXACT_SUCCESS_QUOTIENT2: $T = 6;
const DIV_EXACT_SUCCESS_DIVIDEND3: $T = -91;
const DIV_EXACT_SUCCESS_DIVISOR3: $T = 13;
const DIV_EXACT_SUCCESS_QUOTIENT3: $T = -7;
const DIV_EXACT_SUCCESS_DIVIDEND4: $T = -57;
const DIV_EXACT_SUCCESS_DIVISOR4: $T = -3;
const DIV_EXACT_SUCCESS_QUOTIENT4: $T = 19;
test_runtime_and_compiletime! {
fn test_exact_div() {
fn test_div_exact() {
// 42 / 6
assert_eq_const_safe!(Option<$T>: <$T>::checked_exact_div(EXACT_DIV_SUCCESS_DIVIDEND1, EXACT_DIV_SUCCESS_DIVISOR1), Some(EXACT_DIV_SUCCESS_QUOTIENT1));
assert_eq_const_safe!(Option<$T>: <$T>::exact_div(EXACT_DIV_SUCCESS_DIVIDEND1, EXACT_DIV_SUCCESS_DIVISOR1), Some(EXACT_DIV_SUCCESS_QUOTIENT1));
assert_eq_const_safe!(Option<$T>: <$T>::checked_div_exact(DIV_EXACT_SUCCESS_DIVIDEND1, DIV_EXACT_SUCCESS_DIVISOR1), Some(DIV_EXACT_SUCCESS_QUOTIENT1));
assert_eq_const_safe!(Option<$T>: <$T>::div_exact(DIV_EXACT_SUCCESS_DIVIDEND1, DIV_EXACT_SUCCESS_DIVISOR1), Some(DIV_EXACT_SUCCESS_QUOTIENT1));
// 18 / 3
assert_eq_const_safe!(Option<$T>: <$T>::checked_exact_div(EXACT_DIV_SUCCESS_DIVIDEND2, EXACT_DIV_SUCCESS_DIVISOR2), Some(EXACT_DIV_SUCCESS_QUOTIENT2));
assert_eq_const_safe!(Option<$T>: <$T>::exact_div(EXACT_DIV_SUCCESS_DIVIDEND2, EXACT_DIV_SUCCESS_DIVISOR2), Some(EXACT_DIV_SUCCESS_QUOTIENT2));
assert_eq_const_safe!(Option<$T>: <$T>::checked_div_exact(DIV_EXACT_SUCCESS_DIVIDEND2, DIV_EXACT_SUCCESS_DIVISOR2), Some(DIV_EXACT_SUCCESS_QUOTIENT2));
assert_eq_const_safe!(Option<$T>: <$T>::div_exact(DIV_EXACT_SUCCESS_DIVIDEND2, DIV_EXACT_SUCCESS_DIVISOR2), Some(DIV_EXACT_SUCCESS_QUOTIENT2));
// -91 / 13
assert_eq_const_safe!(Option<$T>: <$T>::checked_exact_div(EXACT_DIV_SUCCESS_DIVIDEND3, EXACT_DIV_SUCCESS_DIVISOR3), Some(EXACT_DIV_SUCCESS_QUOTIENT3));
assert_eq_const_safe!(Option<$T>: <$T>::exact_div(EXACT_DIV_SUCCESS_DIVIDEND3, EXACT_DIV_SUCCESS_DIVISOR3), Some(EXACT_DIV_SUCCESS_QUOTIENT3));
assert_eq_const_safe!(Option<$T>: <$T>::checked_div_exact(DIV_EXACT_SUCCESS_DIVIDEND3, DIV_EXACT_SUCCESS_DIVISOR3), Some(DIV_EXACT_SUCCESS_QUOTIENT3));
assert_eq_const_safe!(Option<$T>: <$T>::div_exact(DIV_EXACT_SUCCESS_DIVIDEND3, DIV_EXACT_SUCCESS_DIVISOR3), Some(DIV_EXACT_SUCCESS_QUOTIENT3));
// -57 / -3
assert_eq_const_safe!(Option<$T>: <$T>::checked_exact_div(EXACT_DIV_SUCCESS_DIVIDEND4, EXACT_DIV_SUCCESS_DIVISOR4), Some(EXACT_DIV_SUCCESS_QUOTIENT4));
assert_eq_const_safe!(Option<$T>: <$T>::exact_div(EXACT_DIV_SUCCESS_DIVIDEND4, EXACT_DIV_SUCCESS_DIVISOR4), Some(EXACT_DIV_SUCCESS_QUOTIENT4));
assert_eq_const_safe!(Option<$T>: <$T>::checked_div_exact(DIV_EXACT_SUCCESS_DIVIDEND4, DIV_EXACT_SUCCESS_DIVISOR4), Some(DIV_EXACT_SUCCESS_QUOTIENT4));
assert_eq_const_safe!(Option<$T>: <$T>::div_exact(DIV_EXACT_SUCCESS_DIVIDEND4, DIV_EXACT_SUCCESS_DIVISOR4), Some(DIV_EXACT_SUCCESS_QUOTIENT4));
// failures
assert_eq_const_safe!(Option<$T>: <$T>::checked_exact_div(1, 2), None);
assert_eq_const_safe!(Option<$T>: <$T>::exact_div(1, 2), None);
assert_eq_const_safe!(Option<$T>: <$T>::checked_exact_div(<$T>::MIN, -1), None);
assert_eq_const_safe!(Option<$T>: <$T>::checked_exact_div(0, 0), None);
assert_eq_const_safe!(Option<$T>: <$T>::checked_div_exact(1, 2), None);
assert_eq_const_safe!(Option<$T>: <$T>::div_exact(1, 2), None);
assert_eq_const_safe!(Option<$T>: <$T>::checked_div_exact(<$T>::MIN, -1), None);
assert_eq_const_safe!(Option<$T>: <$T>::checked_div_exact(0, 0), None);
}
}
};
+14 -14
View File
@@ -595,27 +595,27 @@ fn test_unbounded_shr() {
}
}
const EXACT_DIV_SUCCESS_DIVIDEND1: $T = 42;
const EXACT_DIV_SUCCESS_DIVISOR1: $T = 6;
const EXACT_DIV_SUCCESS_QUOTIENT1: $T = 7;
const EXACT_DIV_SUCCESS_DIVIDEND2: $T = 18;
const EXACT_DIV_SUCCESS_DIVISOR2: $T = 3;
const EXACT_DIV_SUCCESS_QUOTIENT2: $T = 6;
const DIV_EXACT_SUCCESS_DIVIDEND1: $T = 42;
const DIV_EXACT_SUCCESS_DIVISOR1: $T = 6;
const DIV_EXACT_SUCCESS_QUOTIENT1: $T = 7;
const DIV_EXACT_SUCCESS_DIVIDEND2: $T = 18;
const DIV_EXACT_SUCCESS_DIVISOR2: $T = 3;
const DIV_EXACT_SUCCESS_QUOTIENT2: $T = 6;
test_runtime_and_compiletime! {
fn test_exact_div() {
fn test_div_exact() {
// 42 / 6
assert_eq_const_safe!(Option<$T>: <$T>::checked_exact_div(EXACT_DIV_SUCCESS_DIVIDEND1, EXACT_DIV_SUCCESS_DIVISOR1), Some(EXACT_DIV_SUCCESS_QUOTIENT1));
assert_eq_const_safe!(Option<$T>: <$T>::exact_div(EXACT_DIV_SUCCESS_DIVIDEND1, EXACT_DIV_SUCCESS_DIVISOR1), Some(EXACT_DIV_SUCCESS_QUOTIENT1));
assert_eq_const_safe!(Option<$T>: <$T>::checked_div_exact(DIV_EXACT_SUCCESS_DIVIDEND1, DIV_EXACT_SUCCESS_DIVISOR1), Some(DIV_EXACT_SUCCESS_QUOTIENT1));
assert_eq_const_safe!(Option<$T>: <$T>::div_exact(DIV_EXACT_SUCCESS_DIVIDEND1, DIV_EXACT_SUCCESS_DIVISOR1), Some(DIV_EXACT_SUCCESS_QUOTIENT1));
// 18 / 3
assert_eq_const_safe!(Option<$T>: <$T>::checked_exact_div(EXACT_DIV_SUCCESS_DIVIDEND2, EXACT_DIV_SUCCESS_DIVISOR2), Some(EXACT_DIV_SUCCESS_QUOTIENT2));
assert_eq_const_safe!(Option<$T>: <$T>::exact_div(EXACT_DIV_SUCCESS_DIVIDEND2, EXACT_DIV_SUCCESS_DIVISOR2), Some(EXACT_DIV_SUCCESS_QUOTIENT2));
assert_eq_const_safe!(Option<$T>: <$T>::checked_div_exact(DIV_EXACT_SUCCESS_DIVIDEND2, DIV_EXACT_SUCCESS_DIVISOR2), Some(DIV_EXACT_SUCCESS_QUOTIENT2));
assert_eq_const_safe!(Option<$T>: <$T>::div_exact(DIV_EXACT_SUCCESS_DIVIDEND2, DIV_EXACT_SUCCESS_DIVISOR2), Some(DIV_EXACT_SUCCESS_QUOTIENT2));
// failures
assert_eq_const_safe!(Option<$T>: <$T>::checked_exact_div(1, 2), None);
assert_eq_const_safe!(Option<$T>: <$T>::exact_div(1, 2), None);
assert_eq_const_safe!(Option<$T>: <$T>::checked_exact_div(0, 0), None);
assert_eq_const_safe!(Option<$T>: <$T>::checked_div_exact(1, 2), None);
assert_eq_const_safe!(Option<$T>: <$T>::div_exact(1, 2), None);
assert_eq_const_safe!(Option<$T>: <$T>::checked_div_exact(0, 0), None);
}
}
};