Skip to content

Commit b1e56de

Browse files
committed
Auto merge of #114841 - bvanjoi:fix-114814, r=cuviper
add track_caller for arith ops Fixes #114814 `#[track_caller]` is works, r? `@scottmcm`
2 parents bbefc98 + fc87d6e commit b1e56de

16 files changed

+95
-4
lines changed

library/core/src/internal_macros.rs

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ macro_rules! forward_ref_binop {
3131
type Output = <$t as $imp<$u>>::Output;
3232

3333
#[inline]
34+
#[track_caller]
3435
fn $method(self, other: $u) -> <$t as $imp<$u>>::Output {
3536
$imp::$method(*self, other)
3637
}
@@ -41,6 +42,7 @@ macro_rules! forward_ref_binop {
4142
type Output = <$t as $imp<$u>>::Output;
4243

4344
#[inline]
45+
#[track_caller]
4446
fn $method(self, other: &$u) -> <$t as $imp<$u>>::Output {
4547
$imp::$method(self, *other)
4648
}
@@ -51,6 +53,7 @@ macro_rules! forward_ref_binop {
5153
type Output = <$t as $imp<$u>>::Output;
5254

5355
#[inline]
56+
#[track_caller]
5457
fn $method(self, other: &$u) -> <$t as $imp<$u>>::Output {
5558
$imp::$method(*self, *other)
5659
}
@@ -69,6 +72,7 @@ macro_rules! forward_ref_op_assign {
6972
#[$attr]
7073
impl $imp<&$u> for $t {
7174
#[inline]
75+
#[track_caller]
7276
fn $method(&mut self, other: &$u) {
7377
$imp::$method(self, *other);
7478
}

library/core/src/ops/arith.rs

+10
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ macro_rules! add_impl {
9898
type Output = $t;
9999

100100
#[inline]
101+
#[track_caller]
101102
#[rustc_inherit_overflow_checks]
102103
fn add(self, other: $t) -> $t { self + other }
103104
}
@@ -206,6 +207,7 @@ macro_rules! sub_impl {
206207
type Output = $t;
207208

208209
#[inline]
210+
#[track_caller]
209211
#[rustc_inherit_overflow_checks]
210212
fn sub(self, other: $t) -> $t { self - other }
211213
}
@@ -335,6 +337,7 @@ macro_rules! mul_impl {
335337
type Output = $t;
336338

337339
#[inline]
340+
#[track_caller]
338341
#[rustc_inherit_overflow_checks]
339342
fn mul(self, other: $t) -> $t { self * other }
340343
}
@@ -474,6 +477,7 @@ macro_rules! div_impl_integer {
474477
type Output = $t;
475478

476479
#[inline]
480+
#[track_caller]
477481
fn div(self, other: $t) -> $t { self / other }
478482
}
479483

@@ -575,6 +579,7 @@ macro_rules! rem_impl_integer {
575579
type Output = $t;
576580

577581
#[inline]
582+
#[track_caller]
578583
fn rem(self, other: $t) -> $t { self % other }
579584
}
580585

@@ -749,6 +754,7 @@ macro_rules! add_assign_impl {
749754
#[stable(feature = "op_assign_traits", since = "1.8.0")]
750755
impl AddAssign for $t {
751756
#[inline]
757+
#[track_caller]
752758
#[rustc_inherit_overflow_checks]
753759
fn add_assign(&mut self, other: $t) { *self += other }
754760
}
@@ -815,6 +821,7 @@ macro_rules! sub_assign_impl {
815821
#[stable(feature = "op_assign_traits", since = "1.8.0")]
816822
impl SubAssign for $t {
817823
#[inline]
824+
#[track_caller]
818825
#[rustc_inherit_overflow_checks]
819826
fn sub_assign(&mut self, other: $t) { *self -= other }
820827
}
@@ -872,6 +879,7 @@ macro_rules! mul_assign_impl {
872879
#[stable(feature = "op_assign_traits", since = "1.8.0")]
873880
impl MulAssign for $t {
874881
#[inline]
882+
#[track_caller]
875883
#[rustc_inherit_overflow_checks]
876884
fn mul_assign(&mut self, other: $t) { *self *= other }
877885
}
@@ -929,6 +937,7 @@ macro_rules! div_assign_impl {
929937
#[stable(feature = "op_assign_traits", since = "1.8.0")]
930938
impl DivAssign for $t {
931939
#[inline]
940+
#[track_caller]
932941
fn div_assign(&mut self, other: $t) { *self /= other }
933942
}
934943

@@ -989,6 +998,7 @@ macro_rules! rem_assign_impl {
989998
#[stable(feature = "op_assign_traits", since = "1.8.0")]
990999
impl RemAssign for $t {
9911000
#[inline]
1001+
#[track_caller]
9921002
fn rem_assign(&mut self, other: $t) { *self %= other }
9931003
}
9941004

tests/mir-opt/const_prop/inherit_overflow.main.ConstProp.panic-abort.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
let mut _3: u8;
99
scope 1 {
1010
}
11-
scope 2 (inlined <u8 as Add>::add) {
11+
scope 2 (inlined #[track_caller] <u8 as Add>::add) {
1212
debug self => _2;
1313
debug other => _3;
1414
let mut _4: (u8, bool);

tests/mir-opt/const_prop/inherit_overflow.main.ConstProp.panic-unwind.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
let mut _3: u8;
99
scope 1 {
1010
}
11-
scope 2 (inlined <u8 as Add>::add) {
11+
scope 2 (inlined #[track_caller] <u8 as Add>::add) {
1212
debug self => _2;
1313
debug other => _3;
1414
let mut _4: (u8, bool);

tests/mir-opt/dataflow-const-prop/inherit_overflow.main.DataflowConstProp.panic-abort.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
let mut _3: u8;
99
scope 1 {
1010
}
11-
scope 2 (inlined <u8 as Add>::add) {
11+
scope 2 (inlined #[track_caller] <u8 as Add>::add) {
1212
debug self => _2;
1313
debug other => _3;
1414
let mut _4: (u8, bool);

tests/mir-opt/dataflow-const-prop/inherit_overflow.main.DataflowConstProp.panic-unwind.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
let mut _3: u8;
99
scope 1 {
1010
}
11-
scope 2 (inlined <u8 as Add>::add) {
11+
scope 2 (inlined #[track_caller] <u8 as Add>::add) {
1212
debug self => _2;
1313
debug other => _3;
1414
let mut _4: (u8, bool);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// run-fail
2+
// ignore-wasm32
3+
// error-pattern:location-add-assign-overflow.rs
4+
5+
fn main() {
6+
let mut a: u8 = 255;
7+
a += &1;
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// run-fail
2+
// ignore-wasm32
3+
// error-pattern:location-add-overflow.rs
4+
5+
fn main() {
6+
let _: u8 = 255 + &1;
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// run-fail
2+
// ignore-wasm32
3+
// error-pattern:location-divide-assign-by-zero.rs
4+
5+
fn main() {
6+
let mut a = 1;
7+
a /= &0;
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// run-fail
2+
// ignore-wasm32
3+
// error-pattern:location-divide-by-zero.rs
4+
5+
// https://github.com/rust-lang/rust/issues/114814
6+
7+
fn main() {
8+
let _ = 1 / &0;
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// run-fail
2+
// ignore-wasm32
3+
// error-pattern:location-mod-assign-by-zero.rs
4+
5+
fn main() {
6+
let mut a = 1;
7+
a %= &0;
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// run-fail
2+
// ignore-wasm32
3+
// error-pattern:location-mod-by-zero.rs
4+
5+
fn main() {
6+
let _ = 1 % &0;
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// run-fail
2+
// ignore-wasm32
3+
// error-pattern:location-mul-assign-overflow.rs
4+
5+
fn main() {
6+
let mut a: u8 = 255;
7+
a *= &2;
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// run-fail
2+
// ignore-wasm32
3+
// error-pattern:location-mul-overflow.rs
4+
5+
fn main() {
6+
let _: u8 = 255 * &2;
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// run-fail
2+
// ignore-wasm32
3+
// error-pattern:location-sub-assign-overflow.rs
4+
5+
fn main() {
6+
let mut a: u8 = 0;
7+
a -= &1;
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// run-fail
2+
// ignore-wasm32
3+
// error-pattern:location-sub-overflow.rs
4+
5+
fn main() {
6+
let _: u8 = 0 - &1;
7+
}

0 commit comments

Comments
 (0)