Auto merge of #153480 - RaphiMuehlbacher:track-caller, r=Mark-Simulacrum

Add missing `track_caller` to overflowing trait methods

Fixes rust-lang/rust#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.
This commit is contained in:
bors
2026-03-19 05:52:42 +00:00
2 changed files with 5 additions and 0 deletions
+1
View File
@@ -716,6 +716,7 @@ impl const Neg for $t {
type Output = $t;
#[inline]
#[track_caller]
#[rustc_inherit_overflow_checks]
fn neg(self) -> $t { -self }
}
+4
View File
@@ -484,6 +484,7 @@ impl const Shl<$f> for $t {
type Output = $t;
#[inline]
#[track_caller]
#[rustc_inherit_overflow_checks]
fn shl(self, other: $f) -> $t {
self << other
@@ -606,6 +607,7 @@ impl const Shr<$f> for $t {
type Output = $t;
#[inline]
#[track_caller]
#[rustc_inherit_overflow_checks]
fn shr(self, other: $f) -> $t {
self >> other
@@ -958,6 +960,7 @@ macro_rules! shl_assign_impl {
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
impl const ShlAssign<$f> for $t {
#[inline]
#[track_caller]
#[rustc_inherit_overflow_checks]
fn shl_assign(&mut self, other: $f) {
*self <<= other
@@ -1044,6 +1047,7 @@ macro_rules! shr_assign_impl {
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
impl const ShrAssign<$f> for $t {
#[inline]
#[track_caller]
#[rustc_inherit_overflow_checks]
fn shr_assign(&mut self, other: $f) {
*self >>= other