Skip to content

Commit a824017

Browse files
authored
Rollup merge of rust-lang#147771 - nxsaken:div_shlr_exact, r=dtolnay
Rename `*exact_{div,shr,shl}` to `*{div,shr,shl}_exact` Related to rust-lang#144336 and rust-lang#139911, see rust-lang#139911 (comment). I haven't touched the `exact_div`, `exact_udiv` and `exact_sdiv` intrinsics. Let me know if I should.
2 parents 8e44fa9 + f590ae6 commit a824017

File tree

4 files changed

+93
-93
lines changed

4 files changed

+93
-93
lines changed

library/core/src/num/int_macros.rs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -992,10 +992,10 @@ macro_rules! int_impl {
992992
///
993993
/// ```
994994
/// #![feature(exact_div)]
995-
#[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN + 1).checked_exact_div(-1), Some(", stringify!($Max), "));")]
996-
#[doc = concat!("assert_eq!((-5", stringify!($SelfT), ").checked_exact_div(2), None);")]
997-
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.checked_exact_div(-1), None);")]
998-
#[doc = concat!("assert_eq!((1", stringify!($SelfT), ").checked_exact_div(0), None);")]
995+
#[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN + 1).checked_div_exact(-1), Some(", stringify!($Max), "));")]
996+
#[doc = concat!("assert_eq!((-5", stringify!($SelfT), ").checked_div_exact(2), None);")]
997+
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.checked_div_exact(-1), None);")]
998+
#[doc = concat!("assert_eq!((1", stringify!($SelfT), ").checked_div_exact(0), None);")]
999999
/// ```
10001000
#[unstable(
10011001
feature = "exact_div",
@@ -1004,7 +1004,7 @@ macro_rules! int_impl {
10041004
#[must_use = "this returns the result of the operation, \
10051005
without modifying the original"]
10061006
#[inline]
1007-
pub const fn checked_exact_div(self, rhs: Self) -> Option<Self> {
1007+
pub const fn checked_div_exact(self, rhs: Self) -> Option<Self> {
10081008
if intrinsics::unlikely(rhs == 0 || ((self == Self::MIN) && (rhs == -1))) {
10091009
None
10101010
} else {
@@ -1034,18 +1034,18 @@ macro_rules! int_impl {
10341034
///
10351035
/// ```
10361036
/// #![feature(exact_div)]
1037-
#[doc = concat!("assert_eq!(64", stringify!($SelfT), ".exact_div(2), Some(32));")]
1038-
#[doc = concat!("assert_eq!(64", stringify!($SelfT), ".exact_div(32), Some(2));")]
1039-
#[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN + 1).exact_div(-1), Some(", stringify!($Max), "));")]
1040-
#[doc = concat!("assert_eq!(65", stringify!($SelfT), ".exact_div(2), None);")]
1037+
#[doc = concat!("assert_eq!(64", stringify!($SelfT), ".div_exact(2), Some(32));")]
1038+
#[doc = concat!("assert_eq!(64", stringify!($SelfT), ".div_exact(32), Some(2));")]
1039+
#[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN + 1).div_exact(-1), Some(", stringify!($Max), "));")]
1040+
#[doc = concat!("assert_eq!(65", stringify!($SelfT), ".div_exact(2), None);")]
10411041
/// ```
10421042
/// ```should_panic
10431043
/// #![feature(exact_div)]
1044-
#[doc = concat!("let _ = 64", stringify!($SelfT),".exact_div(0);")]
1044+
#[doc = concat!("let _ = 64", stringify!($SelfT),".div_exact(0);")]
10451045
/// ```
10461046
/// ```should_panic
10471047
/// #![feature(exact_div)]
1048-
#[doc = concat!("let _ = ", stringify!($SelfT), "::MIN.exact_div(-1);")]
1048+
#[doc = concat!("let _ = ", stringify!($SelfT), "::MIN.div_exact(-1);")]
10491049
/// ```
10501050
#[unstable(
10511051
feature = "exact_div",
@@ -1055,7 +1055,7 @@ macro_rules! int_impl {
10551055
without modifying the original"]
10561056
#[inline]
10571057
#[rustc_inherit_overflow_checks]
1058-
pub const fn exact_div(self, rhs: Self) -> Option<Self> {
1058+
pub const fn div_exact(self, rhs: Self) -> Option<Self> {
10591059
if self % rhs != 0 {
10601060
None
10611061
} else {
@@ -1069,18 +1069,18 @@ macro_rules! int_impl {
10691069
///
10701070
/// This results in undefined behavior when `rhs == 0`, `self % rhs != 0`, or
10711071
#[doc = concat!("`self == ", stringify!($SelfT), "::MIN && rhs == -1`,")]
1072-
/// i.e. when [`checked_exact_div`](Self::checked_exact_div) would return `None`.
1072+
/// i.e. when [`checked_div_exact`](Self::checked_div_exact) would return `None`.
10731073
#[unstable(
10741074
feature = "exact_div",
10751075
issue = "139911",
10761076
)]
10771077
#[must_use = "this returns the result of the operation, \
10781078
without modifying the original"]
10791079
#[inline]
1080-
pub const unsafe fn unchecked_exact_div(self, rhs: Self) -> Self {
1080+
pub const unsafe fn unchecked_div_exact(self, rhs: Self) -> Self {
10811081
assert_unsafe_precondition!(
10821082
check_language_ub,
1083-
concat!(stringify!($SelfT), "::unchecked_exact_div cannot overflow, divide by zero, or leave a remainder"),
1083+
concat!(stringify!($SelfT), "::unchecked_div_exact cannot overflow, divide by zero, or leave a remainder"),
10841084
(
10851085
lhs: $SelfT = self,
10861086
rhs: $SelfT = rhs,
@@ -1431,17 +1431,17 @@ macro_rules! int_impl {
14311431
/// ```
14321432
/// #![feature(exact_bitshifts)]
14331433
///
1434-
#[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".exact_shl(4), Some(0x10));")]
1435-
#[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".exact_shl(", stringify!($SelfT), "::BITS - 2), Some(1 << ", stringify!($SelfT), "::BITS - 2));")]
1436-
#[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".exact_shl(", stringify!($SelfT), "::BITS - 1), None);")]
1437-
#[doc = concat!("assert_eq!((-0x2", stringify!($SelfT), ").exact_shl(", stringify!($SelfT), "::BITS - 2), Some(-0x2 << ", stringify!($SelfT), "::BITS - 2));")]
1438-
#[doc = concat!("assert_eq!((-0x2", stringify!($SelfT), ").exact_shl(", stringify!($SelfT), "::BITS - 1), None);")]
1434+
#[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".shl_exact(4), Some(0x10));")]
1435+
#[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".shl_exact(", stringify!($SelfT), "::BITS - 2), Some(1 << ", stringify!($SelfT), "::BITS - 2));")]
1436+
#[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".shl_exact(", stringify!($SelfT), "::BITS - 1), None);")]
1437+
#[doc = concat!("assert_eq!((-0x2", stringify!($SelfT), ").shl_exact(", stringify!($SelfT), "::BITS - 2), Some(-0x2 << ", stringify!($SelfT), "::BITS - 2));")]
1438+
#[doc = concat!("assert_eq!((-0x2", stringify!($SelfT), ").shl_exact(", stringify!($SelfT), "::BITS - 1), None);")]
14391439
/// ```
14401440
#[unstable(feature = "exact_bitshifts", issue = "144336")]
14411441
#[must_use = "this returns the result of the operation, \
14421442
without modifying the original"]
14431443
#[inline]
1444-
pub const fn exact_shl(self, rhs: u32) -> Option<$SelfT> {
1444+
pub const fn shl_exact(self, rhs: u32) -> Option<$SelfT> {
14451445
if rhs < self.leading_zeros() || rhs < self.leading_ones() {
14461446
// SAFETY: rhs is checked above
14471447
Some(unsafe { self.unchecked_shl(rhs) })
@@ -1458,16 +1458,16 @@ macro_rules! int_impl {
14581458
///
14591459
/// This results in undefined behavior when `rhs >= self.leading_zeros() && rhs >=
14601460
/// self.leading_ones()` i.e. when
1461-
#[doc = concat!("[`", stringify!($SelfT), "::exact_shl`]")]
1461+
#[doc = concat!("[`", stringify!($SelfT), "::shl_exact`]")]
14621462
/// would return `None`.
14631463
#[unstable(feature = "exact_bitshifts", issue = "144336")]
14641464
#[must_use = "this returns the result of the operation, \
14651465
without modifying the original"]
14661466
#[inline]
1467-
pub const unsafe fn unchecked_exact_shl(self, rhs: u32) -> $SelfT {
1467+
pub const unsafe fn unchecked_shl_exact(self, rhs: u32) -> $SelfT {
14681468
assert_unsafe_precondition!(
14691469
check_library_ub,
1470-
concat!(stringify!($SelfT), "::unchecked_exact_shl cannot shift out bits that would change the value of the first bit"),
1470+
concat!(stringify!($SelfT), "::unchecked_shl_exact cannot shift out bits that would change the value of the first bit"),
14711471
(
14721472
zeros: u32 = self.leading_zeros(),
14731473
ones: u32 = self.leading_ones(),
@@ -1611,14 +1611,14 @@ macro_rules! int_impl {
16111611
/// ```
16121612
/// #![feature(exact_bitshifts)]
16131613
///
1614-
#[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".exact_shr(4), Some(0x1));")]
1615-
#[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".exact_shr(5), None);")]
1614+
#[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".shr_exact(4), Some(0x1));")]
1615+
#[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".shr_exact(5), None);")]
16161616
/// ```
16171617
#[unstable(feature = "exact_bitshifts", issue = "144336")]
16181618
#[must_use = "this returns the result of the operation, \
16191619
without modifying the original"]
16201620
#[inline]
1621-
pub const fn exact_shr(self, rhs: u32) -> Option<$SelfT> {
1621+
pub const fn shr_exact(self, rhs: u32) -> Option<$SelfT> {
16221622
if rhs <= self.trailing_zeros() && rhs < <$SelfT>::BITS {
16231623
// SAFETY: rhs is checked above
16241624
Some(unsafe { self.unchecked_shr(rhs) })
@@ -1636,16 +1636,16 @@ macro_rules! int_impl {
16361636
/// This results in undefined behavior when `rhs > self.trailing_zeros() || rhs >=
16371637
#[doc = concat!(stringify!($SelfT), "::BITS`")]
16381638
/// i.e. when
1639-
#[doc = concat!("[`", stringify!($SelfT), "::exact_shr`]")]
1639+
#[doc = concat!("[`", stringify!($SelfT), "::shr_exact`]")]
16401640
/// would return `None`.
16411641
#[unstable(feature = "exact_bitshifts", issue = "144336")]
16421642
#[must_use = "this returns the result of the operation, \
16431643
without modifying the original"]
16441644
#[inline]
1645-
pub const unsafe fn unchecked_exact_shr(self, rhs: u32) -> $SelfT {
1645+
pub const unsafe fn unchecked_shr_exact(self, rhs: u32) -> $SelfT {
16461646
assert_unsafe_precondition!(
16471647
check_library_ub,
1648-
concat!(stringify!($SelfT), "::unchecked_exact_shr cannot shift out non-zero bits"),
1648+
concat!(stringify!($SelfT), "::unchecked_shr_exact cannot shift out non-zero bits"),
16491649
(
16501650
zeros: u32 = self.trailing_zeros(),
16511651
bits: u32 = <$SelfT>::BITS,

library/core/src/num/uint_macros.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,10 +1222,10 @@ macro_rules! uint_impl {
12221222
///
12231223
/// ```
12241224
/// #![feature(exact_div)]
1225-
#[doc = concat!("assert_eq!(64", stringify!($SelfT), ".checked_exact_div(2), Some(32));")]
1226-
#[doc = concat!("assert_eq!(64", stringify!($SelfT), ".checked_exact_div(32), Some(2));")]
1227-
#[doc = concat!("assert_eq!(64", stringify!($SelfT), ".checked_exact_div(0), None);")]
1228-
#[doc = concat!("assert_eq!(65", stringify!($SelfT), ".checked_exact_div(2), None);")]
1225+
#[doc = concat!("assert_eq!(64", stringify!($SelfT), ".checked_div_exact(2), Some(32));")]
1226+
#[doc = concat!("assert_eq!(64", stringify!($SelfT), ".checked_div_exact(32), Some(2));")]
1227+
#[doc = concat!("assert_eq!(64", stringify!($SelfT), ".checked_div_exact(0), None);")]
1228+
#[doc = concat!("assert_eq!(65", stringify!($SelfT), ".checked_div_exact(2), None);")]
12291229
/// ```
12301230
#[unstable(
12311231
feature = "exact_div",
@@ -1234,7 +1234,7 @@ macro_rules! uint_impl {
12341234
#[must_use = "this returns the result of the operation, \
12351235
without modifying the original"]
12361236
#[inline]
1237-
pub const fn checked_exact_div(self, rhs: Self) -> Option<Self> {
1237+
pub const fn checked_div_exact(self, rhs: Self) -> Option<Self> {
12381238
if intrinsics::unlikely(rhs == 0) {
12391239
None
12401240
} else {
@@ -1259,9 +1259,9 @@ macro_rules! uint_impl {
12591259
///
12601260
/// ```
12611261
/// #![feature(exact_div)]
1262-
#[doc = concat!("assert_eq!(64", stringify!($SelfT), ".exact_div(2), Some(32));")]
1263-
#[doc = concat!("assert_eq!(64", stringify!($SelfT), ".exact_div(32), Some(2));")]
1264-
#[doc = concat!("assert_eq!(65", stringify!($SelfT), ".exact_div(2), None);")]
1262+
#[doc = concat!("assert_eq!(64", stringify!($SelfT), ".div_exact(2), Some(32));")]
1263+
#[doc = concat!("assert_eq!(64", stringify!($SelfT), ".div_exact(32), Some(2));")]
1264+
#[doc = concat!("assert_eq!(65", stringify!($SelfT), ".div_exact(2), None);")]
12651265
/// ```
12661266
#[unstable(
12671267
feature = "exact_div",
@@ -1271,7 +1271,7 @@ macro_rules! uint_impl {
12711271
without modifying the original"]
12721272
#[inline]
12731273
#[rustc_inherit_overflow_checks]
1274-
pub const fn exact_div(self, rhs: Self) -> Option<Self> {
1274+
pub const fn div_exact(self, rhs: Self) -> Option<Self> {
12751275
if self % rhs != 0 {
12761276
None
12771277
} else {
@@ -1284,18 +1284,18 @@ macro_rules! uint_impl {
12841284
/// # Safety
12851285
///
12861286
/// This results in undefined behavior when `rhs == 0` or `self % rhs != 0`,
1287-
/// i.e. when [`checked_exact_div`](Self::checked_exact_div) would return `None`.
1287+
/// i.e. when [`checked_div_exact`](Self::checked_div_exact) would return `None`.
12881288
#[unstable(
12891289
feature = "exact_div",
12901290
issue = "139911",
12911291
)]
12921292
#[must_use = "this returns the result of the operation, \
12931293
without modifying the original"]
12941294
#[inline]
1295-
pub const unsafe fn unchecked_exact_div(self, rhs: Self) -> Self {
1295+
pub const unsafe fn unchecked_div_exact(self, rhs: Self) -> Self {
12961296
assert_unsafe_precondition!(
12971297
check_language_ub,
1298-
concat!(stringify!($SelfT), "::unchecked_exact_div divide by zero or leave a remainder"),
1298+
concat!(stringify!($SelfT), "::unchecked_div_exact divide by zero or leave a remainder"),
12991299
(
13001300
lhs: $SelfT = self,
13011301
rhs: $SelfT = rhs,
@@ -1830,14 +1830,14 @@ macro_rules! uint_impl {
18301830
/// ```
18311831
/// #![feature(exact_bitshifts)]
18321832
///
1833-
#[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".exact_shl(4), Some(0x10));")]
1834-
#[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".exact_shl(129), None);")]
1833+
#[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".shl_exact(4), Some(0x10));")]
1834+
#[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".shl_exact(129), None);")]
18351835
/// ```
18361836
#[unstable(feature = "exact_bitshifts", issue = "144336")]
18371837
#[must_use = "this returns the result of the operation, \
18381838
without modifying the original"]
18391839
#[inline]
1840-
pub const fn exact_shl(self, rhs: u32) -> Option<$SelfT> {
1840+
pub const fn shl_exact(self, rhs: u32) -> Option<$SelfT> {
18411841
if rhs <= self.leading_zeros() && rhs < <$SelfT>::BITS {
18421842
// SAFETY: rhs is checked above
18431843
Some(unsafe { self.unchecked_shl(rhs) })
@@ -1855,16 +1855,16 @@ macro_rules! uint_impl {
18551855
/// This results in undefined behavior when `rhs > self.leading_zeros() || rhs >=
18561856
#[doc = concat!(stringify!($SelfT), "::BITS`")]
18571857
/// i.e. when
1858-
#[doc = concat!("[`", stringify!($SelfT), "::exact_shl`]")]
1858+
#[doc = concat!("[`", stringify!($SelfT), "::shl_exact`]")]
18591859
/// would return `None`.
18601860
#[unstable(feature = "exact_bitshifts", issue = "144336")]
18611861
#[must_use = "this returns the result of the operation, \
18621862
without modifying the original"]
18631863
#[inline]
1864-
pub const unsafe fn unchecked_exact_shl(self, rhs: u32) -> $SelfT {
1864+
pub const unsafe fn unchecked_shl_exact(self, rhs: u32) -> $SelfT {
18651865
assert_unsafe_precondition!(
18661866
check_library_ub,
1867-
concat!(stringify!($SelfT), "::exact_shl_unchecked cannot shift out non-zero bits"),
1867+
concat!(stringify!($SelfT), "::unchecked_shl_exact cannot shift out non-zero bits"),
18681868
(
18691869
zeros: u32 = self.leading_zeros(),
18701870
bits: u32 = <$SelfT>::BITS,
@@ -2002,14 +2002,14 @@ macro_rules! uint_impl {
20022002
/// ```
20032003
/// #![feature(exact_bitshifts)]
20042004
///
2005-
#[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".exact_shr(4), Some(0x1));")]
2006-
#[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".exact_shr(5), None);")]
2005+
#[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".shr_exact(4), Some(0x1));")]
2006+
#[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".shr_exact(5), None);")]
20072007
/// ```
20082008
#[unstable(feature = "exact_bitshifts", issue = "144336")]
20092009
#[must_use = "this returns the result of the operation, \
20102010
without modifying the original"]
20112011
#[inline]
2012-
pub const fn exact_shr(self, rhs: u32) -> Option<$SelfT> {
2012+
pub const fn shr_exact(self, rhs: u32) -> Option<$SelfT> {
20132013
if rhs <= self.trailing_zeros() && rhs < <$SelfT>::BITS {
20142014
// SAFETY: rhs is checked above
20152015
Some(unsafe { self.unchecked_shr(rhs) })
@@ -2027,16 +2027,16 @@ macro_rules! uint_impl {
20272027
/// This results in undefined behavior when `rhs > self.trailing_zeros() || rhs >=
20282028
#[doc = concat!(stringify!($SelfT), "::BITS`")]
20292029
/// i.e. when
2030-
#[doc = concat!("[`", stringify!($SelfT), "::exact_shr`]")]
2030+
#[doc = concat!("[`", stringify!($SelfT), "::shr_exact`]")]
20312031
/// would return `None`.
20322032
#[unstable(feature = "exact_bitshifts", issue = "144336")]
20332033
#[must_use = "this returns the result of the operation, \
20342034
without modifying the original"]
20352035
#[inline]
2036-
pub const unsafe fn unchecked_exact_shr(self, rhs: u32) -> $SelfT {
2036+
pub const unsafe fn unchecked_shr_exact(self, rhs: u32) -> $SelfT {
20372037
assert_unsafe_precondition!(
20382038
check_library_ub,
2039-
concat!(stringify!($SelfT), "::exact_shr_unchecked cannot shift out non-zero bits"),
2039+
concat!(stringify!($SelfT), "::unchecked_shr_exact cannot shift out non-zero bits"),
20402040
(
20412041
zeros: u32 = self.trailing_zeros(),
20422042
bits: u32 = <$SelfT>::BITS,

0 commit comments

Comments
 (0)