Rename {i,u}N::*exact_div to *div_exact

This commit is contained in:
nxsaken 2025-11-02 16:34:36 +04:00
parent 73e6c9ebd9
commit b76267672f
4 changed files with 66 additions and 66 deletions

View file

@ -992,10 +992,10 @@ macro_rules! int_impl {
///
/// ```
/// #![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 @@ macro_rules! int_impl {
#[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 @@ macro_rules! int_impl {
///
/// ```
/// #![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 @@ macro_rules! int_impl {
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 @@ macro_rules! int_impl {
///
/// 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 @@ macro_rules! int_impl {
#[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,

View file

@ -1222,10 +1222,10 @@ macro_rules! uint_impl {
///
/// ```
/// #![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 @@ macro_rules! uint_impl {
#[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 @@ macro_rules! uint_impl {
///
/// ```
/// #![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 @@ macro_rules! uint_impl {
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 @@ macro_rules! uint_impl {
/// # 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 @@ macro_rules! uint_impl {
#[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,

View file

@ -724,42 +724,42 @@ macro_rules! int_module {
}
}
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);
}
}
};

View file

@ -595,27 +595,27 @@ macro_rules! uint_module {
}
}
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);
}
}
};