Skip to content

Commit 6d17169

Browse files
committed
reword panic comments and add spaces to unlikely branches
1 parent 8c7a5b0 commit 6d17169

File tree

3 files changed

+64
-60
lines changed

3 files changed

+64
-60
lines changed

library/core/src/num/int_macros.rs

+34-34
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ macro_rules! int_impl {
451451
#[inline]
452452
pub const fn checked_add(self, rhs: Self) -> Option<Self> {
453453
let (a, b) = self.overflowing_add(rhs);
454-
if unlikely!(b) {None} else {Some(a)}
454+
if unlikely!(b) { None } else { Some(a) }
455455
}
456456

457457
/// Strict integer addition. Computes `self + rhs`, panicking
@@ -461,7 +461,7 @@ macro_rules! int_impl {
461461
///
462462
/// ## Overflow behavior
463463
///
464-
/// This function will always panic on overflow, regardless of if overflow checks are enabled.
464+
/// This function will always panic on overflow, regardless of whether overflow checks are enabled.
465465
///
466466
/// # Examples
467467
///
@@ -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 unlikely!(b) { overflow_panic::add() } else { a }
488488
}
489489

490490
/// Unchecked integer addition. Computes `self + rhs`, assuming overflow
@@ -531,7 +531,7 @@ macro_rules! int_impl {
531531
#[inline]
532532
pub const fn checked_add_unsigned(self, rhs: $UnsignedT) -> Option<Self> {
533533
let (a, b) = self.overflowing_add_unsigned(rhs);
534-
if unlikely!(b) {None} else {Some(a)}
534+
if unlikely!(b) { None } else { Some(a) }
535535
}
536536

537537
/// Strict addition with an unsigned integer. Computes `self + rhs`,
@@ -541,7 +541,7 @@ macro_rules! int_impl {
541541
///
542542
/// ## Overflow behavior
543543
///
544-
/// This function will always panic on overflow, regardless of if overflow checks are enabled.
544+
/// This function will always panic on overflow, regardless of whether overflow checks are enabled.
545545
///
546546
/// # Examples
547547
///
@@ -564,7 +564,7 @@ macro_rules! int_impl {
564564
#[track_caller]
565565
pub const fn strict_add_unsigned(self, rhs: $UnsignedT) -> Self {
566566
let (a, b) = self.overflowing_add_unsigned(rhs);
567-
if unlikely!(b) {overflow_panic::add()} else {a}
567+
if unlikely!(b) { overflow_panic::add() } else { a }
568568
}
569569

570570
/// Checked integer subtraction. Computes `self - rhs`, returning `None` if
@@ -585,7 +585,7 @@ macro_rules! int_impl {
585585
#[inline]
586586
pub const fn checked_sub(self, rhs: Self) -> Option<Self> {
587587
let (a, b) = self.overflowing_sub(rhs);
588-
if unlikely!(b) {None} else {Some(a)}
588+
if unlikely!(b) { None } else { Some(a) }
589589
}
590590

591591
/// Strict integer subtraction. Computes `self - rhs`, panicking if
@@ -595,7 +595,7 @@ macro_rules! int_impl {
595595
///
596596
/// ## Overflow behavior
597597
///
598-
/// This function will always panic on overflow, regardless of if overflow checks are enabled.
598+
/// This function will always panic on overflow, regardless of whether overflow checks are enabled.
599599
///
600600
/// # Examples
601601
///
@@ -618,7 +618,7 @@ macro_rules! int_impl {
618618
#[track_caller]
619619
pub const fn strict_sub(self, rhs: Self) -> Self {
620620
let (a, b) = self.overflowing_sub(rhs);
621-
if unlikely!(b) {overflow_panic::sub()} else {a}
621+
if unlikely!(b) { overflow_panic::sub() } else { a }
622622
}
623623

624624
/// Unchecked integer subtraction. Computes `self - rhs`, assuming overflow
@@ -665,7 +665,7 @@ macro_rules! int_impl {
665665
#[inline]
666666
pub const fn checked_sub_unsigned(self, rhs: $UnsignedT) -> Option<Self> {
667667
let (a, b) = self.overflowing_sub_unsigned(rhs);
668-
if unlikely!(b) {None} else {Some(a)}
668+
if unlikely!(b) { None } else { Some(a) }
669669
}
670670

671671
/// Strict subtraction with an unsigned integer. Computes `self - rhs`,
@@ -675,7 +675,7 @@ macro_rules! int_impl {
675675
///
676676
/// ## Overflow behavior
677677
///
678-
/// This function will always panic on overflow, regardless of if overflow checks are enabled.
678+
/// This function will always panic on overflow, regardless of whether overflow checks are enabled.
679679
///
680680
/// # Examples
681681
///
@@ -698,7 +698,7 @@ macro_rules! int_impl {
698698
#[track_caller]
699699
pub const fn strict_sub_unsigned(self, rhs: $UnsignedT) -> Self {
700700
let (a, b) = self.overflowing_sub_unsigned(rhs);
701-
if unlikely!(b) {overflow_panic::sub()} else {a}
701+
if unlikely!(b) { overflow_panic::sub() } else { a }
702702
}
703703

704704
/// Checked integer multiplication. Computes `self * rhs`, returning `None` if
@@ -719,7 +719,7 @@ macro_rules! int_impl {
719719
#[inline]
720720
pub const fn checked_mul(self, rhs: Self) -> Option<Self> {
721721
let (a, b) = self.overflowing_mul(rhs);
722-
if unlikely!(b) {None} else {Some(a)}
722+
if unlikely!(b) { None } else { Some(a) }
723723
}
724724

725725
/// Strict integer multiplication. Computes `self * rhs`, panicking if
@@ -729,7 +729,7 @@ macro_rules! int_impl {
729729
///
730730
/// ## Overflow behavior
731731
///
732-
/// This function will always panic on overflow, regardless of if overflow checks are enabled.
732+
/// This function will always panic on overflow, regardless of whether overflow checks are enabled.
733733
///
734734
/// # Examples
735735
///
@@ -752,7 +752,7 @@ macro_rules! int_impl {
752752
#[track_caller]
753753
pub const fn strict_mul(self, rhs: Self) -> Self {
754754
let (a, b) = self.overflowing_mul(rhs);
755-
if unlikely!(b) {overflow_panic::mul()} else {a}
755+
if unlikely!(b) { overflow_panic::mul() } else { a }
756756
}
757757

758758
/// Unchecked integer multiplication. Computes `self * rhs`, assuming overflow
@@ -816,7 +816,7 @@ macro_rules! int_impl {
816816
///
817817
/// ## Overflow behavior
818818
///
819-
/// This function will always panic on overflow, regardless of if overflow checks are enabled.
819+
/// This function will always panic on overflow, regardless of whether overflow checks are enabled.
820820
///
821821
/// The only case where such an overflow can occur is when one divides `MIN / -1` on a signed type (where
822822
/// `MIN` is the negative minimal value for the type); this is equivalent to `-MIN`, a positive value
@@ -848,7 +848,7 @@ macro_rules! int_impl {
848848
#[track_caller]
849849
pub const fn strict_div(self, rhs: Self) -> Self {
850850
let (a, b) = self.overflowing_div(rhs);
851-
if unlikely!(b) {overflow_panic::div()} else {a}
851+
if unlikely!(b) { overflow_panic::div() } else { a }
852852
}
853853

854854
/// Checked Euclidean division. Computes `self.div_euclid(rhs)`,
@@ -886,7 +886,7 @@ macro_rules! int_impl {
886886
///
887887
/// ## Overflow behavior
888888
///
889-
/// This function will always panic on overflow, regardless of if overflow checks are enabled.
889+
/// This function will always panic on overflow, regardless of whether overflow checks are enabled.
890890
///
891891
/// The only case where such an overflow can occur is when one divides `MIN / -1` on a signed type (where
892892
/// `MIN` is the negative minimal value for the type); this is equivalent to `-MIN`, a positive value
@@ -918,7 +918,7 @@ macro_rules! int_impl {
918918
#[track_caller]
919919
pub const fn strict_div_euclid(self, rhs: Self) -> Self {
920920
let (a, b) = self.overflowing_div_euclid(rhs);
921-
if unlikely!(b) {overflow_panic::div()} else {a}
921+
if unlikely!(b) { overflow_panic::div() } else { a }
922922
}
923923

924924
/// Checked integer remainder. Computes `self % rhs`, returning `None` if
@@ -956,7 +956,7 @@ macro_rules! int_impl {
956956
///
957957
/// ## Overflow behavior
958958
///
959-
/// This function will always panic on overflow, regardless of if overflow checks are enabled.
959+
/// This function will always panic on overflow, regardless of whether overflow checks are enabled.
960960
///
961961
/// The only case where such an overflow can occur is `x % y` for `MIN / -1` on a
962962
/// signed type (where `MIN` is the negative minimal value), which is invalid due to implementation artifacts.
@@ -987,7 +987,7 @@ macro_rules! int_impl {
987987
#[track_caller]
988988
pub const fn strict_rem(self, rhs: Self) -> Self {
989989
let (a, b) = self.overflowing_rem(rhs);
990-
if unlikely!(b) {overflow_panic::rem()} else {a}
990+
if unlikely!(b) { overflow_panic::rem() } else { a }
991991
}
992992

993993
/// Checked Euclidean remainder. Computes `self.rem_euclid(rhs)`, returning `None`
@@ -1025,7 +1025,7 @@ macro_rules! int_impl {
10251025
///
10261026
/// ## Overflow behavior
10271027
///
1028-
/// This function will always panic on overflow, regardless of if overflow checks are enabled.
1028+
/// This function will always panic on overflow, regardless of whether overflow checks are enabled.
10291029
///
10301030
/// The only case where such an overflow can occur is `x % y` for `MIN / -1` on a
10311031
/// signed type (where `MIN` is the negative minimal value), which is invalid due to implementation artifacts.
@@ -1056,7 +1056,7 @@ macro_rules! int_impl {
10561056
#[track_caller]
10571057
pub const fn strict_rem_euclid(self, rhs: Self) -> Self {
10581058
let (a, b) = self.overflowing_rem_euclid(rhs);
1059-
if unlikely!(b) {overflow_panic::rem()} else {a}
1059+
if unlikely!(b) { overflow_panic::rem() } else { a }
10601060
}
10611061

10621062
/// Checked negation. Computes `-self`, returning `None` if `self == MIN`.
@@ -1076,7 +1076,7 @@ macro_rules! int_impl {
10761076
#[inline]
10771077
pub const fn checked_neg(self) -> Option<Self> {
10781078
let (a, b) = self.overflowing_neg();
1079-
if unlikely!(b) {None} else {Some(a)}
1079+
if unlikely!(b) { None } else { Some(a) }
10801080
}
10811081

10821082
/// Unchecked negation. Computes `-self`, assuming overflow cannot occur.
@@ -1110,7 +1110,7 @@ macro_rules! int_impl {
11101110
///
11111111
/// ## Overflow behavior
11121112
///
1113-
/// This function will always panic on overflow, regardless of if overflow checks are enabled.
1113+
/// This function will always panic on overflow, regardless of whether overflow checks are enabled.
11141114
///
11151115
/// # Examples
11161116
///
@@ -1133,7 +1133,7 @@ macro_rules! int_impl {
11331133
#[track_caller]
11341134
pub const fn strict_neg(self) -> Self {
11351135
let (a, b) = self.overflowing_neg();
1136-
if unlikely!(b) {overflow_panic::neg()} else {a}
1136+
if unlikely!(b) { overflow_panic::neg() } else { a }
11371137
}
11381138

11391139
/// Checked shift left. Computes `self << rhs`, returning `None` if `rhs` is larger
@@ -1154,7 +1154,7 @@ macro_rules! int_impl {
11541154
#[inline]
11551155
pub const fn checked_shl(self, rhs: u32) -> Option<Self> {
11561156
let (a, b) = self.overflowing_shl(rhs);
1157-
if unlikely!(b) {None} else {Some(a)}
1157+
if unlikely!(b) { None } else { Some(a) }
11581158
}
11591159

11601160
/// Strict shift left. Computes `self << rhs`, panicking if `rhs` is larger
@@ -1164,7 +1164,7 @@ macro_rules! int_impl {
11641164
///
11651165
/// ## Overflow behavior
11661166
///
1167-
/// This function will always panic on overflow, regardless of if overflow checks are enabled.
1167+
/// This function will always panic on overflow, regardless of whether overflow checks are enabled.
11681168
///
11691169
/// # Examples
11701170
///
@@ -1187,7 +1187,7 @@ macro_rules! int_impl {
11871187
#[track_caller]
11881188
pub const fn strict_shl(self, rhs: u32) -> Self {
11891189
let (a, b) = self.overflowing_shl(rhs);
1190-
if unlikely!(b) {overflow_panic::shl()} else {a}
1190+
if unlikely!(b) { overflow_panic::shl() } else { a }
11911191
}
11921192

11931193
/// Unchecked shift left. Computes `self << rhs`, assuming that
@@ -1235,7 +1235,7 @@ macro_rules! int_impl {
12351235
#[inline]
12361236
pub const fn checked_shr(self, rhs: u32) -> Option<Self> {
12371237
let (a, b) = self.overflowing_shr(rhs);
1238-
if unlikely!(b) {None} else {Some(a)}
1238+
if unlikely!(b) { None } else { Some(a) }
12391239
}
12401240

12411241
/// Strict shift right. Computes `self >> rhs`, panicking `rhs` is
@@ -1245,7 +1245,7 @@ macro_rules! int_impl {
12451245
///
12461246
/// ## Overflow behavior
12471247
///
1248-
/// This function will always panic on overflow, regardless of if overflow checks are enabled.
1248+
/// This function will always panic on overflow, regardless of whether overflow checks are enabled.
12491249
///
12501250
/// # Examples
12511251
///
@@ -1268,7 +1268,7 @@ macro_rules! int_impl {
12681268
#[track_caller]
12691269
pub const fn strict_shr(self, rhs: u32) -> Self {
12701270
let (a, b) = self.overflowing_shr(rhs);
1271-
if unlikely!(b) {overflow_panic::shr()} else {a}
1271+
if unlikely!(b) { overflow_panic::shr() } else { a }
12721272
}
12731273

12741274
/// Unchecked shift right. Computes `self >> rhs`, assuming that
@@ -1329,7 +1329,7 @@ macro_rules! int_impl {
13291329
///
13301330
/// ## Overflow behavior
13311331
///
1332-
/// This function will always panic on overflow, regardless of if overflow checks are enabled.
1332+
/// This function will always panic on overflow, regardless of whether overflow checks are enabled.
13331333
///
13341334
/// # Examples
13351335
///
@@ -1403,7 +1403,7 @@ macro_rules! int_impl {
14031403
///
14041404
/// ## Overflow behavior
14051405
///
1406-
/// This function will always panic on overflow, regardless of if overflow checks are enabled.
1406+
/// This function will always panic on overflow, regardless of whether overflow checks are enabled.
14071407
///
14081408
/// # Examples
14091409
///

library/core/src/num/overflow_panic.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//! Functions for panicking on overflow.
2+
//!
3+
//! In particular, these are used by the `strict_` methods on integers.
4+
15
#[cold]
26
#[track_caller]
37
pub const fn add() -> ! {

0 commit comments

Comments
 (0)