Skip to content

Commit 8c7a5b0

Browse files
committed
add #[track_caller] to improve panic locations
1 parent fb349a2 commit 8c7a5b0

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

library/core/src/num/int_macros.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ macro_rules! int_impl {
481481
#[must_use = "this returns the result of the operation, \
482482
without modifying the original"]
483483
#[inline]
484+
#[track_caller]
484485
pub const fn strict_add(self, rhs: Self) -> Self {
485486
let (a, b) = self.overflowing_add(rhs);
486487
if unlikely!(b) {overflow_panic::add()} else {a}
@@ -560,6 +561,7 @@ macro_rules! int_impl {
560561
#[must_use = "this returns the result of the operation, \
561562
without modifying the original"]
562563
#[inline]
564+
#[track_caller]
563565
pub const fn strict_add_unsigned(self, rhs: $UnsignedT) -> Self {
564566
let (a, b) = self.overflowing_add_unsigned(rhs);
565567
if unlikely!(b) {overflow_panic::add()} else {a}
@@ -613,6 +615,7 @@ macro_rules! int_impl {
613615
#[must_use = "this returns the result of the operation, \
614616
without modifying the original"]
615617
#[inline]
618+
#[track_caller]
616619
pub const fn strict_sub(self, rhs: Self) -> Self {
617620
let (a, b) = self.overflowing_sub(rhs);
618621
if unlikely!(b) {overflow_panic::sub()} else {a}
@@ -692,6 +695,7 @@ macro_rules! int_impl {
692695
#[must_use = "this returns the result of the operation, \
693696
without modifying the original"]
694697
#[inline]
698+
#[track_caller]
695699
pub const fn strict_sub_unsigned(self, rhs: $UnsignedT) -> Self {
696700
let (a, b) = self.overflowing_sub_unsigned(rhs);
697701
if unlikely!(b) {overflow_panic::sub()} else {a}
@@ -745,6 +749,7 @@ macro_rules! int_impl {
745749
#[must_use = "this returns the result of the operation, \
746750
without modifying the original"]
747751
#[inline]
752+
#[track_caller]
748753
pub const fn strict_mul(self, rhs: Self) -> Self {
749754
let (a, b) = self.overflowing_mul(rhs);
750755
if unlikely!(b) {overflow_panic::mul()} else {a}
@@ -840,6 +845,7 @@ macro_rules! int_impl {
840845
#[must_use = "this returns the result of the operation, \
841846
without modifying the original"]
842847
#[inline]
848+
#[track_caller]
843849
pub const fn strict_div(self, rhs: Self) -> Self {
844850
let (a, b) = self.overflowing_div(rhs);
845851
if unlikely!(b) {overflow_panic::div()} else {a}
@@ -909,6 +915,7 @@ macro_rules! int_impl {
909915
#[must_use = "this returns the result of the operation, \
910916
without modifying the original"]
911917
#[inline]
918+
#[track_caller]
912919
pub const fn strict_div_euclid(self, rhs: Self) -> Self {
913920
let (a, b) = self.overflowing_div_euclid(rhs);
914921
if unlikely!(b) {overflow_panic::div()} else {a}
@@ -977,6 +984,7 @@ macro_rules! int_impl {
977984
#[must_use = "this returns the result of the operation, \
978985
without modifying the original"]
979986
#[inline]
987+
#[track_caller]
980988
pub const fn strict_rem(self, rhs: Self) -> Self {
981989
let (a, b) = self.overflowing_rem(rhs);
982990
if unlikely!(b) {overflow_panic::rem()} else {a}
@@ -1045,6 +1053,7 @@ macro_rules! int_impl {
10451053
#[must_use = "this returns the result of the operation, \
10461054
without modifying the original"]
10471055
#[inline]
1056+
#[track_caller]
10481057
pub const fn strict_rem_euclid(self, rhs: Self) -> Self {
10491058
let (a, b) = self.overflowing_rem_euclid(rhs);
10501059
if unlikely!(b) {overflow_panic::rem()} else {a}
@@ -1121,6 +1130,7 @@ macro_rules! int_impl {
11211130
#[must_use = "this returns the result of the operation, \
11221131
without modifying the original"]
11231132
#[inline]
1133+
#[track_caller]
11241134
pub const fn strict_neg(self) -> Self {
11251135
let (a, b) = self.overflowing_neg();
11261136
if unlikely!(b) {overflow_panic::neg()} else {a}
@@ -1174,6 +1184,7 @@ macro_rules! int_impl {
11741184
#[must_use = "this returns the result of the operation, \
11751185
without modifying the original"]
11761186
#[inline]
1187+
#[track_caller]
11771188
pub const fn strict_shl(self, rhs: u32) -> Self {
11781189
let (a, b) = self.overflowing_shl(rhs);
11791190
if unlikely!(b) {overflow_panic::shl()} else {a}
@@ -1254,6 +1265,7 @@ macro_rules! int_impl {
12541265
#[must_use = "this returns the result of the operation, \
12551266
without modifying the original"]
12561267
#[inline]
1268+
#[track_caller]
12571269
pub const fn strict_shr(self, rhs: u32) -> Self {
12581270
let (a, b) = self.overflowing_shr(rhs);
12591271
if unlikely!(b) {overflow_panic::shr()} else {a}
@@ -1337,6 +1349,7 @@ macro_rules! int_impl {
13371349
#[must_use = "this returns the result of the operation, \
13381350
without modifying the original"]
13391351
#[inline]
1352+
#[track_caller]
13401353
pub const fn strict_abs(self) -> Self {
13411354
if self.is_negative() {
13421355
self.strict_neg()
@@ -1410,6 +1423,7 @@ macro_rules! int_impl {
14101423
#[must_use = "this returns the result of the operation, \
14111424
without modifying the original"]
14121425
#[inline]
1426+
#[track_caller]
14131427
pub const fn strict_pow(self, mut exp: u32) -> Self {
14141428
if exp == 0 {
14151429
return 1;

library/core/src/num/uint_macros.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ macro_rules! uint_impl {
489489
#[must_use = "this returns the result of the operation, \
490490
without modifying the original"]
491491
#[inline]
492+
#[track_caller]
492493
pub const fn strict_add(self, rhs: Self) -> Self {
493494
let (a, b) = self.overflowing_add(rhs);
494495
if unlikely!(b) {overflow_panic::add()} else {a}
@@ -574,6 +575,7 @@ macro_rules! uint_impl {
574575
#[must_use = "this returns the result of the operation, \
575576
without modifying the original"]
576577
#[inline]
578+
#[track_caller]
577579
pub const fn strict_add_signed(self, rhs: $SignedT) -> Self {
578580
let (a, b) = self.overflowing_add_signed(rhs);
579581
if unlikely!(b) {overflow_panic::add()} else {a}
@@ -627,6 +629,7 @@ macro_rules! uint_impl {
627629
#[must_use = "this returns the result of the operation, \
628630
without modifying the original"]
629631
#[inline]
632+
#[track_caller]
630633
pub const fn strict_sub(self, rhs: Self) -> Self {
631634
let (a, b) = self.overflowing_sub(rhs);
632635
if unlikely!(b) {overflow_panic::sub()} else {a}
@@ -706,6 +709,7 @@ macro_rules! uint_impl {
706709
#[must_use = "this returns the result of the operation, \
707710
without modifying the original"]
708711
#[inline]
712+
#[track_caller]
709713
pub const fn strict_mul(self, rhs: Self) -> Self {
710714
let (a, b) = self.overflowing_mul(rhs);
711715
if unlikely!(b) {overflow_panic::mul()} else {a}
@@ -786,6 +790,7 @@ macro_rules! uint_impl {
786790
#[must_use = "this returns the result of the operation, \
787791
without modifying the original"]
788792
#[inline(always)]
793+
#[track_caller]
789794
pub const fn strict_div(self, rhs: Self) -> Self {
790795
self / rhs
791796
}
@@ -840,6 +845,7 @@ macro_rules! uint_impl {
840845
#[must_use = "this returns the result of the operation, \
841846
without modifying the original"]
842847
#[inline(always)]
848+
#[track_caller]
843849
pub const fn strict_div_euclid(self, rhs: Self) -> Self {
844850
self / rhs
845851
}
@@ -894,6 +900,7 @@ macro_rules! uint_impl {
894900
#[must_use = "this returns the result of the operation, \
895901
without modifying the original"]
896902
#[inline(always)]
903+
#[track_caller]
897904
pub const fn strict_rem(self, rhs: Self) -> Self {
898905
self % rhs
899906
}
@@ -949,6 +956,7 @@ macro_rules! uint_impl {
949956
#[must_use = "this returns the result of the operation, \
950957
without modifying the original"]
951958
#[inline(always)]
959+
#[track_caller]
952960
pub const fn strict_rem_euclid(self, rhs: Self) -> Self {
953961
self % rhs
954962
}
@@ -1171,6 +1179,7 @@ macro_rules! uint_impl {
11711179
#[must_use = "this returns the result of the operation, \
11721180
without modifying the original"]
11731181
#[inline]
1182+
#[track_caller]
11741183
pub const fn strict_neg(self) -> Self {
11751184
let (a, b) = self.overflowing_neg();
11761185
if unlikely!(b) {overflow_panic::neg()} else {a}
@@ -1224,6 +1233,7 @@ macro_rules! uint_impl {
12241233
#[must_use = "this returns the result of the operation, \
12251234
without modifying the original"]
12261235
#[inline]
1236+
#[track_caller]
12271237
pub const fn strict_shl(self, rhs: u32) -> Self {
12281238
let (a, b) = self.overflowing_shl(rhs);
12291239
if unlikely!(b) {overflow_panic::shl()} else {a}
@@ -1304,6 +1314,7 @@ macro_rules! uint_impl {
13041314
#[must_use = "this returns the result of the operation, \
13051315
without modifying the original"]
13061316
#[inline]
1317+
#[track_caller]
13071318
pub const fn strict_shr(self, rhs: u32) -> Self {
13081319
let (a, b) = self.overflowing_shr(rhs);
13091320
if unlikely!(b) {overflow_panic::shr()} else {a}
@@ -1402,6 +1413,7 @@ macro_rules! uint_impl {
14021413
#[must_use = "this returns the result of the operation, \
14031414
without modifying the original"]
14041415
#[inline]
1416+
#[track_caller]
14051417
pub const fn strict_pow(self, mut exp: u32) -> Self {
14061418
if exp == 0 {
14071419
return 1;

0 commit comments

Comments
 (0)