Skip to content

Commit 48d3855

Browse files
authored
Rollup merge of #46473 - frewsxcv:frewsxcv-param-name, r=TimNN
Consistent parameter name for numeric ‘checked’ operations. Some checked operations use `rhs` as a parameter name, and some use `other`. For the sake of consistency, unify everything under the `rhs` name. Fixes #46308.
2 parents 909a8de + a2d87d8 commit 48d3855

File tree

1 file changed

+69
-69
lines changed

1 file changed

+69
-69
lines changed

src/libcore/num/mod.rs

+69-69
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ macro_rules! int_impl {
380380
if cfg!(target_endian = "little") { self } else { self.swap_bytes() }
381381
}
382382

383-
/// Checked integer addition. Computes `self + other`, returning `None`
383+
/// Checked integer addition. Computes `self + rhs`, returning `None`
384384
/// if overflow occurred.
385385
///
386386
/// # Examples
@@ -393,12 +393,12 @@ macro_rules! int_impl {
393393
/// ```
394394
#[stable(feature = "rust1", since = "1.0.0")]
395395
#[inline]
396-
pub fn checked_add(self, other: Self) -> Option<Self> {
397-
let (a, b) = self.overflowing_add(other);
396+
pub fn checked_add(self, rhs: Self) -> Option<Self> {
397+
let (a, b) = self.overflowing_add(rhs);
398398
if b {None} else {Some(a)}
399399
}
400400

401-
/// Checked integer subtraction. Computes `self - other`, returning
401+
/// Checked integer subtraction. Computes `self - rhs`, returning
402402
/// `None` if underflow occurred.
403403
///
404404
/// # Examples
@@ -411,12 +411,12 @@ macro_rules! int_impl {
411411
/// ```
412412
#[stable(feature = "rust1", since = "1.0.0")]
413413
#[inline]
414-
pub fn checked_sub(self, other: Self) -> Option<Self> {
415-
let (a, b) = self.overflowing_sub(other);
414+
pub fn checked_sub(self, rhs: Self) -> Option<Self> {
415+
let (a, b) = self.overflowing_sub(rhs);
416416
if b {None} else {Some(a)}
417417
}
418418

419-
/// Checked integer multiplication. Computes `self * other`, returning
419+
/// Checked integer multiplication. Computes `self * rhs`, returning
420420
/// `None` if underflow or overflow occurred.
421421
///
422422
/// # Examples
@@ -429,13 +429,13 @@ macro_rules! int_impl {
429429
/// ```
430430
#[stable(feature = "rust1", since = "1.0.0")]
431431
#[inline]
432-
pub fn checked_mul(self, other: Self) -> Option<Self> {
433-
let (a, b) = self.overflowing_mul(other);
432+
pub fn checked_mul(self, rhs: Self) -> Option<Self> {
433+
let (a, b) = self.overflowing_mul(rhs);
434434
if b {None} else {Some(a)}
435435
}
436436

437-
/// Checked integer division. Computes `self / other`, returning `None`
438-
/// if `other == 0` or the operation results in underflow or overflow.
437+
/// Checked integer division. Computes `self / rhs`, returning `None`
438+
/// if `rhs == 0` or the operation results in underflow or overflow.
439439
///
440440
/// # Examples
441441
///
@@ -448,16 +448,16 @@ macro_rules! int_impl {
448448
/// ```
449449
#[stable(feature = "rust1", since = "1.0.0")]
450450
#[inline]
451-
pub fn checked_div(self, other: Self) -> Option<Self> {
452-
if other == 0 || (self == Self::min_value() && other == -1) {
451+
pub fn checked_div(self, rhs: Self) -> Option<Self> {
452+
if rhs == 0 || (self == Self::min_value() && rhs == -1) {
453453
None
454454
} else {
455-
Some(unsafe { intrinsics::unchecked_div(self, other) })
455+
Some(unsafe { intrinsics::unchecked_div(self, rhs) })
456456
}
457457
}
458458

459-
/// Checked integer remainder. Computes `self % other`, returning `None`
460-
/// if `other == 0` or the operation results in underflow or overflow.
459+
/// Checked integer remainder. Computes `self % rhs`, returning `None`
460+
/// if `rhs == 0` or the operation results in underflow or overflow.
461461
///
462462
/// # Examples
463463
///
@@ -472,11 +472,11 @@ macro_rules! int_impl {
472472
/// ```
473473
#[stable(feature = "wrapping", since = "1.7.0")]
474474
#[inline]
475-
pub fn checked_rem(self, other: Self) -> Option<Self> {
476-
if other == 0 || (self == Self::min_value() && other == -1) {
475+
pub fn checked_rem(self, rhs: Self) -> Option<Self> {
476+
if rhs == 0 || (self == Self::min_value() && rhs == -1) {
477477
None
478478
} else {
479-
Some(unsafe { intrinsics::unchecked_rem(self, other) })
479+
Some(unsafe { intrinsics::unchecked_rem(self, rhs) })
480480
}
481481
}
482482

@@ -559,7 +559,7 @@ macro_rules! int_impl {
559559
}
560560
}
561561

562-
/// Saturating integer addition. Computes `self + other`, saturating at
562+
/// Saturating integer addition. Computes `self + rhs`, saturating at
563563
/// the numeric bounds instead of overflowing.
564564
///
565565
/// # Examples
@@ -572,15 +572,15 @@ macro_rules! int_impl {
572572
/// ```
573573
#[stable(feature = "rust1", since = "1.0.0")]
574574
#[inline]
575-
pub fn saturating_add(self, other: Self) -> Self {
576-
match self.checked_add(other) {
575+
pub fn saturating_add(self, rhs: Self) -> Self {
576+
match self.checked_add(rhs) {
577577
Some(x) => x,
578-
None if other >= 0 => Self::max_value(),
578+
None if rhs >= 0 => Self::max_value(),
579579
None => Self::min_value(),
580580
}
581581
}
582582

583-
/// Saturating integer subtraction. Computes `self - other`, saturating
583+
/// Saturating integer subtraction. Computes `self - rhs`, saturating
584584
/// at the numeric bounds instead of overflowing.
585585
///
586586
/// # Examples
@@ -593,15 +593,15 @@ macro_rules! int_impl {
593593
/// ```
594594
#[stable(feature = "rust1", since = "1.0.0")]
595595
#[inline]
596-
pub fn saturating_sub(self, other: Self) -> Self {
597-
match self.checked_sub(other) {
596+
pub fn saturating_sub(self, rhs: Self) -> Self {
597+
match self.checked_sub(rhs) {
598598
Some(x) => x,
599-
None if other >= 0 => Self::min_value(),
599+
None if rhs >= 0 => Self::min_value(),
600600
None => Self::max_value(),
601601
}
602602
}
603603

604-
/// Saturating integer multiplication. Computes `self * other`,
604+
/// Saturating integer multiplication. Computes `self * rhs`,
605605
/// saturating at the numeric bounds instead of overflowing.
606606
///
607607
/// # Examples
@@ -617,17 +617,17 @@ macro_rules! int_impl {
617617
/// ```
618618
#[stable(feature = "wrapping", since = "1.7.0")]
619619
#[inline]
620-
pub fn saturating_mul(self, other: Self) -> Self {
621-
self.checked_mul(other).unwrap_or_else(|| {
622-
if (self < 0 && other < 0) || (self > 0 && other > 0) {
620+
pub fn saturating_mul(self, rhs: Self) -> Self {
621+
self.checked_mul(rhs).unwrap_or_else(|| {
622+
if (self < 0 && rhs < 0) || (self > 0 && rhs > 0) {
623623
Self::max_value()
624624
} else {
625625
Self::min_value()
626626
}
627627
})
628628
}
629629

630-
/// Wrapping (modular) addition. Computes `self + other`,
630+
/// Wrapping (modular) addition. Computes `self + rhs`,
631631
/// wrapping around at the boundary of the type.
632632
///
633633
/// # Examples
@@ -646,7 +646,7 @@ macro_rules! int_impl {
646646
}
647647
}
648648

649-
/// Wrapping (modular) subtraction. Computes `self - other`,
649+
/// Wrapping (modular) subtraction. Computes `self - rhs`,
650650
/// wrapping around at the boundary of the type.
651651
///
652652
/// # Examples
@@ -666,7 +666,7 @@ macro_rules! int_impl {
666666
}
667667

668668
/// Wrapping (modular) multiplication. Computes `self *
669-
/// other`, wrapping around at the boundary of the type.
669+
/// rhs`, wrapping around at the boundary of the type.
670670
///
671671
/// # Examples
672672
///
@@ -684,7 +684,7 @@ macro_rules! int_impl {
684684
}
685685
}
686686

687-
/// Wrapping (modular) division. Computes `self / other`,
687+
/// Wrapping (modular) division. Computes `self / rhs`,
688688
/// wrapping around at the boundary of the type.
689689
///
690690
/// The only case where such wrapping can occur is when one
@@ -712,7 +712,7 @@ macro_rules! int_impl {
712712
self.overflowing_div(rhs).0
713713
}
714714

715-
/// Wrapping (modular) remainder. Computes `self % other`,
715+
/// Wrapping (modular) remainder. Computes `self % rhs`,
716716
/// wrapping around at the boundary of the type.
717717
///
718718
/// Such wrap-around never actually occurs mathematically;
@@ -1573,7 +1573,7 @@ macro_rules! uint_impl {
15731573
if cfg!(target_endian = "little") { self } else { self.swap_bytes() }
15741574
}
15751575

1576-
/// Checked integer addition. Computes `self + other`, returning `None`
1576+
/// Checked integer addition. Computes `self + rhs`, returning `None`
15771577
/// if overflow occurred.
15781578
///
15791579
/// # Examples
@@ -1586,12 +1586,12 @@ macro_rules! uint_impl {
15861586
/// ```
15871587
#[stable(feature = "rust1", since = "1.0.0")]
15881588
#[inline]
1589-
pub fn checked_add(self, other: Self) -> Option<Self> {
1590-
let (a, b) = self.overflowing_add(other);
1589+
pub fn checked_add(self, rhs: Self) -> Option<Self> {
1590+
let (a, b) = self.overflowing_add(rhs);
15911591
if b {None} else {Some(a)}
15921592
}
15931593

1594-
/// Checked integer subtraction. Computes `self - other`, returning
1594+
/// Checked integer subtraction. Computes `self - rhs`, returning
15951595
/// `None` if underflow occurred.
15961596
///
15971597
/// # Examples
@@ -1604,12 +1604,12 @@ macro_rules! uint_impl {
16041604
/// ```
16051605
#[stable(feature = "rust1", since = "1.0.0")]
16061606
#[inline]
1607-
pub fn checked_sub(self, other: Self) -> Option<Self> {
1608-
let (a, b) = self.overflowing_sub(other);
1607+
pub fn checked_sub(self, rhs: Self) -> Option<Self> {
1608+
let (a, b) = self.overflowing_sub(rhs);
16091609
if b {None} else {Some(a)}
16101610
}
16111611

1612-
/// Checked integer multiplication. Computes `self * other`, returning
1612+
/// Checked integer multiplication. Computes `self * rhs`, returning
16131613
/// `None` if underflow or overflow occurred.
16141614
///
16151615
/// # Examples
@@ -1622,13 +1622,13 @@ macro_rules! uint_impl {
16221622
/// ```
16231623
#[stable(feature = "rust1", since = "1.0.0")]
16241624
#[inline]
1625-
pub fn checked_mul(self, other: Self) -> Option<Self> {
1626-
let (a, b) = self.overflowing_mul(other);
1625+
pub fn checked_mul(self, rhs: Self) -> Option<Self> {
1626+
let (a, b) = self.overflowing_mul(rhs);
16271627
if b {None} else {Some(a)}
16281628
}
16291629

1630-
/// Checked integer division. Computes `self / other`, returning `None`
1631-
/// if `other == 0` or the operation results in underflow or overflow.
1630+
/// Checked integer division. Computes `self / rhs`, returning `None`
1631+
/// if `rhs == 0` or the operation results in underflow or overflow.
16321632
///
16331633
/// # Examples
16341634
///
@@ -1640,15 +1640,15 @@ macro_rules! uint_impl {
16401640
/// ```
16411641
#[stable(feature = "rust1", since = "1.0.0")]
16421642
#[inline]
1643-
pub fn checked_div(self, other: Self) -> Option<Self> {
1644-
match other {
1643+
pub fn checked_div(self, rhs: Self) -> Option<Self> {
1644+
match rhs {
16451645
0 => None,
1646-
other => Some(unsafe { intrinsics::unchecked_div(self, other) }),
1646+
rhs => Some(unsafe { intrinsics::unchecked_div(self, rhs) }),
16471647
}
16481648
}
16491649

1650-
/// Checked integer remainder. Computes `self % other`, returning `None`
1651-
/// if `other == 0` or the operation results in underflow or overflow.
1650+
/// Checked integer remainder. Computes `self % rhs`, returning `None`
1651+
/// if `rhs == 0` or the operation results in underflow or overflow.
16521652
///
16531653
/// # Examples
16541654
///
@@ -1660,11 +1660,11 @@ macro_rules! uint_impl {
16601660
/// ```
16611661
#[stable(feature = "wrapping", since = "1.7.0")]
16621662
#[inline]
1663-
pub fn checked_rem(self, other: Self) -> Option<Self> {
1664-
if other == 0 {
1663+
pub fn checked_rem(self, rhs: Self) -> Option<Self> {
1664+
if rhs == 0 {
16651665
None
16661666
} else {
1667-
Some(unsafe { intrinsics::unchecked_rem(self, other) })
1667+
Some(unsafe { intrinsics::unchecked_rem(self, rhs) })
16681668
}
16691669
}
16701670

@@ -1724,7 +1724,7 @@ macro_rules! uint_impl {
17241724
if b {None} else {Some(a)}
17251725
}
17261726

1727-
/// Saturating integer addition. Computes `self + other`, saturating at
1727+
/// Saturating integer addition. Computes `self + rhs`, saturating at
17281728
/// the numeric bounds instead of overflowing.
17291729
///
17301730
/// # Examples
@@ -1737,14 +1737,14 @@ macro_rules! uint_impl {
17371737
/// ```
17381738
#[stable(feature = "rust1", since = "1.0.0")]
17391739
#[inline]
1740-
pub fn saturating_add(self, other: Self) -> Self {
1741-
match self.checked_add(other) {
1740+
pub fn saturating_add(self, rhs: Self) -> Self {
1741+
match self.checked_add(rhs) {
17421742
Some(x) => x,
17431743
None => Self::max_value(),
17441744
}
17451745
}
17461746

1747-
/// Saturating integer subtraction. Computes `self - other`, saturating
1747+
/// Saturating integer subtraction. Computes `self - rhs`, saturating
17481748
/// at the numeric bounds instead of overflowing.
17491749
///
17501750
/// # Examples
@@ -1757,14 +1757,14 @@ macro_rules! uint_impl {
17571757
/// ```
17581758
#[stable(feature = "rust1", since = "1.0.0")]
17591759
#[inline]
1760-
pub fn saturating_sub(self, other: Self) -> Self {
1761-
match self.checked_sub(other) {
1760+
pub fn saturating_sub(self, rhs: Self) -> Self {
1761+
match self.checked_sub(rhs) {
17621762
Some(x) => x,
17631763
None => Self::min_value(),
17641764
}
17651765
}
17661766

1767-
/// Saturating integer multiplication. Computes `self * other`,
1767+
/// Saturating integer multiplication. Computes `self * rhs`,
17681768
/// saturating at the numeric bounds instead of overflowing.
17691769
///
17701770
/// # Examples
@@ -1779,11 +1779,11 @@ macro_rules! uint_impl {
17791779
/// ```
17801780
#[stable(feature = "wrapping", since = "1.7.0")]
17811781
#[inline]
1782-
pub fn saturating_mul(self, other: Self) -> Self {
1783-
self.checked_mul(other).unwrap_or(Self::max_value())
1782+
pub fn saturating_mul(self, rhs: Self) -> Self {
1783+
self.checked_mul(rhs).unwrap_or(Self::max_value())
17841784
}
17851785

1786-
/// Wrapping (modular) addition. Computes `self + other`,
1786+
/// Wrapping (modular) addition. Computes `self + rhs`,
17871787
/// wrapping around at the boundary of the type.
17881788
///
17891789
/// # Examples
@@ -1802,7 +1802,7 @@ macro_rules! uint_impl {
18021802
}
18031803
}
18041804

1805-
/// Wrapping (modular) subtraction. Computes `self - other`,
1805+
/// Wrapping (modular) subtraction. Computes `self - rhs`,
18061806
/// wrapping around at the boundary of the type.
18071807
///
18081808
/// # Examples
@@ -1822,7 +1822,7 @@ macro_rules! uint_impl {
18221822
}
18231823

18241824
/// Wrapping (modular) multiplication. Computes `self *
1825-
/// other`, wrapping around at the boundary of the type.
1825+
/// rhs`, wrapping around at the boundary of the type.
18261826
///
18271827
/// # Examples
18281828
///
@@ -1840,7 +1840,7 @@ macro_rules! uint_impl {
18401840
}
18411841
}
18421842

1843-
/// Wrapping (modular) division. Computes `self / other`.
1843+
/// Wrapping (modular) division. Computes `self / rhs`.
18441844
/// Wrapped division on unsigned types is just normal division.
18451845
/// There's no way wrapping could ever happen.
18461846
/// This function exists, so that all operations
@@ -1859,7 +1859,7 @@ macro_rules! uint_impl {
18591859
self / rhs
18601860
}
18611861

1862-
/// Wrapping (modular) remainder. Computes `self % other`.
1862+
/// Wrapping (modular) remainder. Computes `self % rhs`.
18631863
/// Wrapped remainder calculation on unsigned types is
18641864
/// just the regular remainder calculation.
18651865
/// There's no way wrapping could ever happen.

0 commit comments

Comments
 (0)