Skip to content

Commit d03d6c0

Browse files
committed
Auto merge of rust-lang#126750 - scottmcm:less-unlikely, r=jhpratt
Stop using `unlikely` in `strict_*` methods The `strict_*` methods don't need (un)likely, because the `overflow_panic` calls are all `#[cold]`, [meaning](https://llvm.org/docs/LangRef.html#function-attributes) that LLVM knows any branch to them is unlikely without us needing to say so. r? libs
2 parents f1b0d54 + a314f73 commit d03d6c0

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

library/core/src/num/int_macros.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ macro_rules! int_impl {
484484
#[track_caller]
485485
pub const fn strict_add(self, rhs: Self) -> Self {
486486
let (a, b) = self.overflowing_add(rhs);
487-
if unlikely!(b) { overflow_panic::add() } else { a }
487+
if b { overflow_panic::add() } else { a }
488488
}
489489

490490
/// Unchecked integer addition. Computes `self + rhs`, assuming overflow
@@ -580,7 +580,7 @@ macro_rules! int_impl {
580580
#[track_caller]
581581
pub const fn strict_add_unsigned(self, rhs: $UnsignedT) -> Self {
582582
let (a, b) = self.overflowing_add_unsigned(rhs);
583-
if unlikely!(b) { overflow_panic::add() } else { a }
583+
if b { overflow_panic::add() } else { a }
584584
}
585585

586586
/// Checked integer subtraction. Computes `self - rhs`, returning `None` if
@@ -636,7 +636,7 @@ macro_rules! int_impl {
636636
#[track_caller]
637637
pub const fn strict_sub(self, rhs: Self) -> Self {
638638
let (a, b) = self.overflowing_sub(rhs);
639-
if unlikely!(b) { overflow_panic::sub() } else { a }
639+
if b { overflow_panic::sub() } else { a }
640640
}
641641

642642
/// Unchecked integer subtraction. Computes `self - rhs`, assuming overflow
@@ -732,7 +732,7 @@ macro_rules! int_impl {
732732
#[track_caller]
733733
pub const fn strict_sub_unsigned(self, rhs: $UnsignedT) -> Self {
734734
let (a, b) = self.overflowing_sub_unsigned(rhs);
735-
if unlikely!(b) { overflow_panic::sub() } else { a }
735+
if b { overflow_panic::sub() } else { a }
736736
}
737737

738738
/// Checked integer multiplication. Computes `self * rhs`, returning `None` if
@@ -788,7 +788,7 @@ macro_rules! int_impl {
788788
#[track_caller]
789789
pub const fn strict_mul(self, rhs: Self) -> Self {
790790
let (a, b) = self.overflowing_mul(rhs);
791-
if unlikely!(b) { overflow_panic::mul() } else { a }
791+
if b { overflow_panic::mul() } else { a }
792792
}
793793

794794
/// Unchecked integer multiplication. Computes `self * rhs`, assuming overflow
@@ -902,7 +902,7 @@ macro_rules! int_impl {
902902
#[track_caller]
903903
pub const fn strict_div(self, rhs: Self) -> Self {
904904
let (a, b) = self.overflowing_div(rhs);
905-
if unlikely!(b) { overflow_panic::div() } else { a }
905+
if b { overflow_panic::div() } else { a }
906906
}
907907

908908
/// Checked Euclidean division. Computes `self.div_euclid(rhs)`,
@@ -976,7 +976,7 @@ macro_rules! int_impl {
976976
#[track_caller]
977977
pub const fn strict_div_euclid(self, rhs: Self) -> Self {
978978
let (a, b) = self.overflowing_div_euclid(rhs);
979-
if unlikely!(b) { overflow_panic::div() } else { a }
979+
if b { overflow_panic::div() } else { a }
980980
}
981981

982982
/// Checked integer remainder. Computes `self % rhs`, returning `None` if
@@ -1049,7 +1049,7 @@ macro_rules! int_impl {
10491049
#[track_caller]
10501050
pub const fn strict_rem(self, rhs: Self) -> Self {
10511051
let (a, b) = self.overflowing_rem(rhs);
1052-
if unlikely!(b) { overflow_panic::rem() } else { a }
1052+
if b { overflow_panic::rem() } else { a }
10531053
}
10541054

10551055
/// Checked Euclidean remainder. Computes `self.rem_euclid(rhs)`, returning `None`
@@ -1122,7 +1122,7 @@ macro_rules! int_impl {
11221122
#[track_caller]
11231123
pub const fn strict_rem_euclid(self, rhs: Self) -> Self {
11241124
let (a, b) = self.overflowing_rem_euclid(rhs);
1125-
if unlikely!(b) { overflow_panic::rem() } else { a }
1125+
if b { overflow_panic::rem() } else { a }
11261126
}
11271127

11281128
/// Checked negation. Computes `-self`, returning `None` if `self == MIN`.
@@ -1210,7 +1210,7 @@ macro_rules! int_impl {
12101210
#[track_caller]
12111211
pub const fn strict_neg(self) -> Self {
12121212
let (a, b) = self.overflowing_neg();
1213-
if unlikely!(b) { overflow_panic::neg() } else { a }
1213+
if b { overflow_panic::neg() } else { a }
12141214
}
12151215

12161216
/// Checked shift left. Computes `self << rhs`, returning `None` if `rhs` is larger
@@ -1273,7 +1273,7 @@ macro_rules! int_impl {
12731273
#[track_caller]
12741274
pub const fn strict_shl(self, rhs: u32) -> Self {
12751275
let (a, b) = self.overflowing_shl(rhs);
1276-
if unlikely!(b) { overflow_panic::shl() } else { a }
1276+
if b { overflow_panic::shl() } else { a }
12771277
}
12781278

12791279
/// Unchecked shift left. Computes `self << rhs`, assuming that
@@ -1371,7 +1371,7 @@ macro_rules! int_impl {
13711371
#[track_caller]
13721372
pub const fn strict_shr(self, rhs: u32) -> Self {
13731373
let (a, b) = self.overflowing_shr(rhs);
1374-
if unlikely!(b) { overflow_panic::shr() } else { a }
1374+
if b { overflow_panic::shr() } else { a }
13751375
}
13761376

13771377
/// Unchecked shift right. Computes `self >> rhs`, assuming that

library/core/src/num/uint_macros.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ macro_rules! uint_impl {
491491
#[track_caller]
492492
pub const fn strict_add(self, rhs: Self) -> Self {
493493
let (a, b) = self.overflowing_add(rhs);
494-
if unlikely!(b) { overflow_panic ::add()} else {a}
494+
if b { overflow_panic::add() } else { a }
495495
}
496496

497497
/// Unchecked integer addition. Computes `self + rhs`, assuming overflow
@@ -593,7 +593,7 @@ macro_rules! uint_impl {
593593
#[track_caller]
594594
pub const fn strict_add_signed(self, rhs: $SignedT) -> Self {
595595
let (a, b) = self.overflowing_add_signed(rhs);
596-
if unlikely!(b) { overflow_panic ::add()} else {a}
596+
if b { overflow_panic::add() } else { a }
597597
}
598598

599599
/// Checked integer subtraction. Computes `self - rhs`, returning
@@ -658,7 +658,7 @@ macro_rules! uint_impl {
658658
#[track_caller]
659659
pub const fn strict_sub(self, rhs: Self) -> Self {
660660
let (a, b) = self.overflowing_sub(rhs);
661-
if unlikely!(b) { overflow_panic ::sub()} else {a}
661+
if b { overflow_panic::sub() } else { a }
662662
}
663663

664664
/// Unchecked integer subtraction. Computes `self - rhs`, assuming overflow
@@ -779,7 +779,7 @@ macro_rules! uint_impl {
779779
#[track_caller]
780780
pub const fn strict_mul(self, rhs: Self) -> Self {
781781
let (a, b) = self.overflowing_mul(rhs);
782-
if unlikely!(b) { overflow_panic ::mul()} else {a}
782+
if b { overflow_panic::mul() } else { a }
783783
}
784784

785785
/// Unchecked integer multiplication. Computes `self * rhs`, assuming overflow
@@ -1304,7 +1304,7 @@ macro_rules! uint_impl {
13041304
#[track_caller]
13051305
pub const fn strict_neg(self) -> Self {
13061306
let (a, b) = self.overflowing_neg();
1307-
if unlikely!(b) { overflow_panic::neg() } else { a }
1307+
if b { overflow_panic::neg() } else { a }
13081308
}
13091309

13101310
/// Checked shift left. Computes `self << rhs`, returning `None`
@@ -1367,7 +1367,7 @@ macro_rules! uint_impl {
13671367
#[track_caller]
13681368
pub const fn strict_shl(self, rhs: u32) -> Self {
13691369
let (a, b) = self.overflowing_shl(rhs);
1370-
if unlikely!(b) { overflow_panic::shl() } else { a }
1370+
if b { overflow_panic::shl() } else { a }
13711371
}
13721372

13731373
/// Unchecked shift left. Computes `self << rhs`, assuming that
@@ -1465,7 +1465,7 @@ macro_rules! uint_impl {
14651465
#[track_caller]
14661466
pub const fn strict_shr(self, rhs: u32) -> Self {
14671467
let (a, b) = self.overflowing_shr(rhs);
1468-
if unlikely!(b) { overflow_panic::shr() } else { a }
1468+
if b { overflow_panic::shr() } else { a }
14691469
}
14701470

14711471
/// Unchecked shift right. Computes `self >> rhs`, assuming that

0 commit comments

Comments
 (0)