Skip to content

Commit 16b9bb7

Browse files
committed
get rid of the internal unlikely macro
1 parent 3854e16 commit 16b9bb7

5 files changed

Lines changed: 31 additions & 33 deletions

File tree

‎library/core/src/intrinsics.rs‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,10 @@ pub const unsafe fn assume(b: bool) {
986986
/// any safety invariants.
987987
///
988988
/// This intrinsic does not have a stable counterpart.
989-
#[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_likely", issue = "none"))]
989+
#[cfg_attr(
990+
bootstrap,
991+
rustc_const_stable(feature = "const_likely", since = "CURRENT_RUSTC_VERSION")
992+
)]
990993
#[cfg_attr(not(bootstrap), rustc_const_stable_indirect)]
991994
#[unstable(feature = "core_intrinsics", issue = "none")]
992995
#[rustc_intrinsic]
@@ -1007,7 +1010,10 @@ pub const fn likely(b: bool) -> bool {
10071010
/// any safety invariants.
10081011
///
10091012
/// This intrinsic does not have a stable counterpart.
1010-
#[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_likely", issue = "none"))]
1013+
#[cfg_attr(
1014+
bootstrap,
1015+
rustc_const_stable(feature = "const_likely", since = "CURRENT_RUSTC_VERSION")
1016+
)]
10111017
#[cfg_attr(not(bootstrap), rustc_const_stable_indirect)]
10121018
#[unstable(feature = "core_intrinsics", issue = "none")]
10131019
#[rustc_intrinsic]

‎library/core/src/num/int_macros.rs‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ macro_rules! int_impl {
449449
#[inline]
450450
pubconstfn checked_add(self, rhs:Self) -> Option<Self> {
451451
let(a, b) = self.overflowing_add(rhs);
452-
if unlikely!(b){None} else {Some(a)}
452+
ifintrinsics::unlikely(b){None} else {Some(a)}
453453
}
454454

455455
/// Strict integer addition. Computes `self + rhs`, panicking
@@ -545,7 +545,7 @@ macro_rules! int_impl {
545545
#[inline]
546546
pubconstfn checked_add_unsigned(self, rhs: $UnsignedT) -> Option<Self> {
547547
let(a, b) = self.overflowing_add_unsigned(rhs);
548-
if unlikely!(b){None} else {Some(a)}
548+
ifintrinsics::unlikely(b){None} else {Some(a)}
549549
}
550550

551551
/// Strict addition with an unsigned integer. Computes `self + rhs`,
@@ -601,7 +601,7 @@ macro_rules! int_impl {
601601
#[inline]
602602
pubconstfn checked_sub(self, rhs:Self) -> Option<Self> {
603603
let(a, b) = self.overflowing_sub(rhs);
604-
if unlikely!(b){None} else {Some(a)}
604+
ifintrinsics::unlikely(b){None} else {Some(a)}
605605
}
606606

607607
/// Strict integer subtraction. Computes `self - rhs`, panicking if
@@ -697,7 +697,7 @@ macro_rules! int_impl {
697697
#[inline]
698698
pubconstfn checked_sub_unsigned(self, rhs: $UnsignedT) -> Option<Self> {
699699
let(a, b) = self.overflowing_sub_unsigned(rhs);
700-
if unlikely!(b){None} else {Some(a)}
700+
ifintrinsics::unlikely(b){None} else {Some(a)}
701701
}
702702

703703
/// Strict subtraction with an unsigned integer. Computes `self - rhs`,
@@ -753,7 +753,7 @@ macro_rules! int_impl {
753753
#[inline]
754754
pubconstfn checked_mul(self, rhs:Self) -> Option<Self> {
755755
let(a, b) = self.overflowing_mul(rhs);
756-
if unlikely!(b){None} else {Some(a)}
756+
ifintrinsics::unlikely(b){None} else {Some(a)}
757757
}
758758

759759
/// Strict integer multiplication. Computes `self * rhs`, panicking if
@@ -849,7 +849,7 @@ macro_rules! int_impl {
849849
without modifying the original"]
850850
#[inline]
851851
pubconstfn checked_div(self, rhs:Self) -> Option<Self> {
852-
if unlikely!(rhs == 0 || ((self == Self::MIN) && (rhs == -1))){
852+
ifintrinsics::unlikely(rhs == 0 || ((self == Self::MIN) && (rhs == -1))){
853853
None
854854
} else {
855855
// SAFETY: div by zero and by INT_MIN have been checked above
@@ -924,7 +924,7 @@ macro_rules! int_impl {
924924
#[inline]
925925
pubconstfn checked_div_euclid(self, rhs:Self) -> Option<Self> {
926926
// Using `&` helps LLVM see that it is the same check made in division.
927-
if unlikely!(rhs == 0 || ((self == Self::MIN)&(rhs == -1))){
927+
ifintrinsics::unlikely(rhs == 0 || ((self == Self::MIN)&(rhs == -1))){
928928
None
929929
} else {
930930
Some(self.div_euclid(rhs))
@@ -997,7 +997,7 @@ macro_rules! int_impl {
997997
without modifying the original"]
998998
#[inline]
999999
pubconstfn checked_rem(self, rhs:Self) -> Option<Self> {
1000-
if unlikely!(rhs == 0 || ((self == Self::MIN) && (rhs == -1))){
1000+
ifintrinsics::unlikely(rhs == 0 || ((self == Self::MIN) && (rhs == -1))){
10011001
None
10021002
} else {
10031003
// SAFETY: div by zero and by INT_MIN have been checked above
@@ -1071,7 +1071,7 @@ macro_rules! int_impl {
10711071
#[inline]
10721072
pubconstfn checked_rem_euclid(self, rhs:Self) -> Option<Self> {
10731073
// Using `&` helps LLVM see that it is the same check made in division.
1074-
if unlikely!(rhs == 0 || ((self == Self::MIN)&(rhs == -1))){
1074+
ifintrinsics::unlikely(rhs == 0 || ((self == Self::MIN)&(rhs == -1))){
10751075
None
10761076
} else {
10771077
Some(self.rem_euclid(rhs))
@@ -1142,7 +1142,7 @@ macro_rules! int_impl {
11421142
#[inline]
11431143
pubconstfn checked_neg(self) -> Option<Self> {
11441144
let(a, b) = self.overflowing_neg();
1145-
if unlikely!(b){None} else {Some(a)}
1145+
ifintrinsics::unlikely(b){None} else {Some(a)}
11461146
}
11471147

11481148
/// Unchecked negation. Computes `-self`, assuming overflow cannot occur.
@@ -2564,7 +2564,7 @@ macro_rules! int_impl {
25642564
without modifying the original"]
25652565
pubconstfn overflowing_div(self, rhs:Self) -> (Self,bool){
25662566
// Using `&` helps LLVM see that it is the same check made in division.
2567-
if unlikely!((self == Self::MIN)&(rhs == -1)){
2567+
ifintrinsics::unlikely((self == Self::MIN)&(rhs == -1)){
25682568
(self,true)
25692569
} else {
25702570
(self / rhs,false)
@@ -2595,7 +2595,7 @@ macro_rules! int_impl {
25952595
without modifying the original"]
25962596
pubconstfn overflowing_div_euclid(self, rhs:Self) -> (Self,bool){
25972597
// Using `&` helps LLVM see that it is the same check made in division.
2598-
if unlikely!((self == Self::MIN)&(rhs == -1)){
2598+
ifintrinsics::unlikely((self == Self::MIN)&(rhs == -1)){
25992599
(self,true)
26002600
} else {
26012601
(self.div_euclid(rhs),false)
@@ -2625,7 +2625,7 @@ macro_rules! int_impl {
26252625
#[must_use = "this returns the result of the operation, \
26262626
without modifying the original"]
26272627
pubconstfn overflowing_rem(self, rhs:Self) -> (Self,bool){
2628-
if unlikely!(rhs == -1){
2628+
ifintrinsics::unlikely(rhs == -1){
26292629
(0,self == Self::MIN)
26302630
} else {
26312631
(self % rhs,false)
@@ -2657,7 +2657,7 @@ macro_rules! int_impl {
26572657
#[inline]
26582658
#[track_caller]
26592659
pubconstfn overflowing_rem_euclid(self, rhs:Self) -> (Self,bool){
2660-
if unlikely!(rhs == -1){
2660+
ifintrinsics::unlikely(rhs == -1){
26612661
(0,self == Self::MIN)
26622662
} else {
26632663
(self.rem_euclid(rhs),false)
@@ -2686,7 +2686,7 @@ macro_rules! int_impl {
26862686
without modifying the original"]
26872687
#[allow(unused_attributes)]
26882688
pubconstfn overflowing_neg(self) -> (Self,bool){
2689-
if unlikely!(self == Self::MIN){
2689+
ifintrinsics::unlikely(self == Self::MIN){
26902690
(Self::MIN,true)
26912691
} else {
26922692
(-self,false)

‎library/core/src/num/mod.rs‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@ macro_rules! try_opt {
1616
};
1717
}
1818

19-
#[cfg_attr(bootstrap, allow_internal_unstable(const_likely))]
20-
macro_rules! unlikely {
21-
($e: expr) => {
22-
intrinsics::unlikely($e)
23-
};
24-
}
25-
2619
// Use this when the generated code should differ between signed and unsigned types.
2720
macro_rules! sign_dependent_expr {
2821
(signed ? if signed { $signed_case:expr }if unsigned { $unsigned_case:expr }) => {

‎library/core/src/num/uint_macros.rs‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ macro_rules! uint_impl {
491491
// Per <https://github.com/rust-lang/rust/pull/124114#issuecomment-2066173305>,
492492
// LLVM is happy to re-form the intrinsic later if useful.
493493

494-
if unlikely!(intrinsics::add_with_overflow(self, rhs).1){
494+
ifintrinsics::unlikely(intrinsics::add_with_overflow(self, rhs).1){
495495
None
496496
} else {
497497
// SAFETY: Just checked it doesn't overflow
@@ -593,7 +593,7 @@ macro_rules! uint_impl {
593593
#[inline]
594594
pubconstfn checked_add_signed(self, rhs: $SignedT) -> Option<Self> {
595595
let(a, b) = self.overflowing_add_signed(rhs);
596-
if unlikely!(b){None} else {Some(a)}
596+
ifintrinsics::unlikely(b){None} else {Some(a)}
597597
}
598598

599599
/// Strict addition with a signed integer. Computes `self + rhs`,
@@ -845,7 +845,7 @@ macro_rules! uint_impl {
845845
#[inline]
846846
pubconstfn checked_mul(self, rhs:Self) -> Option<Self> {
847847
let(a, b) = self.overflowing_mul(rhs);
848-
if unlikely!(b){None} else {Some(a)}
848+
ifintrinsics::unlikely(b){None} else {Some(a)}
849849
}
850850

851851
/// Strict integer multiplication. Computes `self * rhs`, panicking if
@@ -940,7 +940,7 @@ macro_rules! uint_impl {
940940
without modifying the original"]
941941
#[inline]
942942
pubconstfn checked_div(self, rhs:Self) -> Option<Self> {
943-
if unlikely!(rhs == 0){
943+
ifintrinsics::unlikely(rhs == 0){
944944
None
945945
} else {
946946
// SAFETY: div by zero has been checked above and unsigned types have no other
@@ -1001,7 +1001,7 @@ macro_rules! uint_impl {
10011001
without modifying the original"]
10021002
#[inline]
10031003
pubconstfn checked_div_euclid(self, rhs:Self) -> Option<Self> {
1004-
if unlikely!(rhs == 0){
1004+
ifintrinsics::unlikely(rhs == 0){
10051005
None
10061006
} else {
10071007
Some(self.div_euclid(rhs))
@@ -1061,7 +1061,7 @@ macro_rules! uint_impl {
10611061
without modifying the original"]
10621062
#[inline]
10631063
pubconstfn checked_rem(self, rhs:Self) -> Option<Self> {
1064-
if unlikely!(rhs == 0){
1064+
ifintrinsics::unlikely(rhs == 0){
10651065
None
10661066
} else {
10671067
// SAFETY: div by zero has been checked above and unsigned types have no other
@@ -1123,7 +1123,7 @@ macro_rules! uint_impl {
11231123
without modifying the original"]
11241124
#[inline]
11251125
pubconstfn checked_rem_euclid(self, rhs:Self) -> Option<Self> {
1126-
if unlikely!(rhs == 0){
1126+
ifintrinsics::unlikely(rhs == 0){
11271127
None
11281128
} else {
11291129
Some(self.rem_euclid(rhs))
@@ -1362,7 +1362,7 @@ macro_rules! uint_impl {
13621362
#[inline]
13631363
pubconstfn checked_neg(self) -> Option<Self> {
13641364
let(a, b) = self.overflowing_neg();
1365-
if unlikely!(b){None} else {Some(a)}
1365+
ifintrinsics::unlikely(b){None} else {Some(a)}
13661366
}
13671367

13681368
/// Strict negation. Computes `-self`, panicking unless `self ==

‎library/core/tests/lib.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// tidy-alphabetical-start
2-
#![cfg_attr(bootstrap, feature(const_likely))]
32
#![cfg_attr(bootstrap, feature(strict_provenance))]
43
#![cfg_attr(not(bootstrap), feature(strict_provenance_lints))]
54
#![cfg_attr(target_has_atomic = "128", feature(integer_atomics))]

0 commit comments

Comments
 (0)