Skip to content

Commit 8b86f48

Browse files
committed
Auto merge of #153480 - RaphiMuehlbacher:track-caller, r=Mark-Simulacrum
Add missing `track_caller` to overflowing trait methods Fixes #152599 by adding `#[track_caller]` to arithmetic trait methods (`Neg`, `Shl`, `ShlAssign`, `Shr` and `ShrAssign`) so overflow panics report the correct call site instead of the trait definition.
2 parents fd0c901 + 9676838 commit 8b86f48

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

library/core/src/ops/arith.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,7 @@ macro_rules! neg_impl {
716716
type Output = $t;
717717

718718
#[inline]
719+
#[track_caller]
719720
#[rustc_inherit_overflow_checks]
720721
fn neg(self) -> $t { -self }
721722
}

library/core/src/ops/bit.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ macro_rules! shl_impl {
484484
type Output = $t;
485485

486486
#[inline]
487+
#[track_caller]
487488
#[rustc_inherit_overflow_checks]
488489
fn shl(self, other: $f) -> $t {
489490
self << other
@@ -606,6 +607,7 @@ macro_rules! shr_impl {
606607
type Output = $t;
607608

608609
#[inline]
610+
#[track_caller]
609611
#[rustc_inherit_overflow_checks]
610612
fn shr(self, other: $f) -> $t {
611613
self >> other
@@ -958,6 +960,7 @@ macro_rules! shl_assign_impl {
958960
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
959961
impl const ShlAssign<$f> for $t {
960962
#[inline]
963+
#[track_caller]
961964
#[rustc_inherit_overflow_checks]
962965
fn shl_assign(&mut self, other: $f) {
963966
*self <<= other
@@ -1044,6 +1047,7 @@ macro_rules! shr_assign_impl {
10441047
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
10451048
impl const ShrAssign<$f> for $t {
10461049
#[inline]
1050+
#[track_caller]
10471051
#[rustc_inherit_overflow_checks]
10481052
fn shr_assign(&mut self, other: $f) {
10491053
*self >>= other

0 commit comments

Comments
 (0)