Skip to content

Commit

Permalink
add track_caller for arith ops
Browse files Browse the repository at this point in the history
  • Loading branch information
bvanjoi committed Nov 23, 2023
1 parent 91f7f26 commit fc87d6e
Show file tree
Hide file tree
Showing 16 changed files with 95 additions and 4 deletions.
4 changes: 4 additions & 0 deletions library/core/src/internal_macros.rs
Expand Up @@ -31,6 +31,7 @@ macro_rules! forward_ref_binop {
type Output = <$t as $imp<$u>>::Output;

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

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

#[inline]
#[track_caller]
fn $method(self, other: &$u) -> <$t as $imp<$u>>::Output {
$imp::$method(*self, *other)
}
Expand All @@ -69,6 +72,7 @@ macro_rules! forward_ref_op_assign {
#[$attr]
impl $imp<&$u> for $t {
#[inline]
#[track_caller]
fn $method(&mut self, other: &$u) {
$imp::$method(self, *other);
}
Expand Down
10 changes: 10 additions & 0 deletions library/core/src/ops/arith.rs
Expand Up @@ -98,6 +98,7 @@ macro_rules! add_impl {
type Output = $t;

#[inline]
#[track_caller]
#[rustc_inherit_overflow_checks]
fn add(self, other: $t) -> $t { self + other }
}
Expand Down Expand Up @@ -206,6 +207,7 @@ macro_rules! sub_impl {
type Output = $t;

#[inline]
#[track_caller]
#[rustc_inherit_overflow_checks]
fn sub(self, other: $t) -> $t { self - other }
}
Expand Down Expand Up @@ -335,6 +337,7 @@ macro_rules! mul_impl {
type Output = $t;

#[inline]
#[track_caller]
#[rustc_inherit_overflow_checks]
fn mul(self, other: $t) -> $t { self * other }
}
Expand Down Expand Up @@ -474,6 +477,7 @@ macro_rules! div_impl_integer {
type Output = $t;

#[inline]
#[track_caller]
fn div(self, other: $t) -> $t { self / other }
}

Expand Down Expand Up @@ -575,6 +579,7 @@ macro_rules! rem_impl_integer {
type Output = $t;

#[inline]
#[track_caller]
fn rem(self, other: $t) -> $t { self % other }
}

Expand Down Expand Up @@ -749,6 +754,7 @@ macro_rules! add_assign_impl {
#[stable(feature = "op_assign_traits", since = "1.8.0")]
impl AddAssign for $t {
#[inline]
#[track_caller]
#[rustc_inherit_overflow_checks]
fn add_assign(&mut self, other: $t) { *self += other }
}
Expand Down Expand Up @@ -815,6 +821,7 @@ macro_rules! sub_assign_impl {
#[stable(feature = "op_assign_traits", since = "1.8.0")]
impl SubAssign for $t {
#[inline]
#[track_caller]
#[rustc_inherit_overflow_checks]
fn sub_assign(&mut self, other: $t) { *self -= other }
}
Expand Down Expand Up @@ -872,6 +879,7 @@ macro_rules! mul_assign_impl {
#[stable(feature = "op_assign_traits", since = "1.8.0")]
impl MulAssign for $t {
#[inline]
#[track_caller]
#[rustc_inherit_overflow_checks]
fn mul_assign(&mut self, other: $t) { *self *= other }
}
Expand Down Expand Up @@ -929,6 +937,7 @@ macro_rules! div_assign_impl {
#[stable(feature = "op_assign_traits", since = "1.8.0")]
impl DivAssign for $t {
#[inline]
#[track_caller]
fn div_assign(&mut self, other: $t) { *self /= other }
}

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

Expand Down
Expand Up @@ -8,7 +8,7 @@
let mut _3: u8;
scope 1 {
}
scope 2 (inlined <u8 as Add>::add) {
scope 2 (inlined #[track_caller] <u8 as Add>::add) {
debug self => _2;
debug other => _3;
let mut _4: (u8, bool);
Expand Down
Expand Up @@ -8,7 +8,7 @@
let mut _3: u8;
scope 1 {
}
scope 2 (inlined <u8 as Add>::add) {
scope 2 (inlined #[track_caller] <u8 as Add>::add) {
debug self => _2;
debug other => _3;
let mut _4: (u8, bool);
Expand Down
Expand Up @@ -8,7 +8,7 @@
let mut _3: u8;
scope 1 {
}
scope 2 (inlined <u8 as Add>::add) {
scope 2 (inlined #[track_caller] <u8 as Add>::add) {
debug self => _2;
debug other => _3;
let mut _4: (u8, bool);
Expand Down
Expand Up @@ -8,7 +8,7 @@
let mut _3: u8;
scope 1 {
}
scope 2 (inlined <u8 as Add>::add) {
scope 2 (inlined #[track_caller] <u8 as Add>::add) {
debug self => _2;
debug other => _3;
let mut _4: (u8, bool);
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/numbers-arithmetic/location-add-assign-overflow.rs
@@ -0,0 +1,8 @@
// run-fail
// ignore-wasm32
// error-pattern:location-add-assign-overflow.rs

fn main() {
let mut a: u8 = 255;
a += &1;
}
7 changes: 7 additions & 0 deletions tests/ui/numbers-arithmetic/location-add-overflow.rs
@@ -0,0 +1,7 @@
// run-fail
// ignore-wasm32
// error-pattern:location-add-overflow.rs

fn main() {
let _: u8 = 255 + &1;
}
8 changes: 8 additions & 0 deletions tests/ui/numbers-arithmetic/location-divide-assign-by-zero.rs
@@ -0,0 +1,8 @@
// run-fail
// ignore-wasm32
// error-pattern:location-divide-assign-by-zero.rs

fn main() {
let mut a = 1;
a /= &0;
}
9 changes: 9 additions & 0 deletions tests/ui/numbers-arithmetic/location-divide-by-zero.rs
@@ -0,0 +1,9 @@
// run-fail
// ignore-wasm32
// error-pattern:location-divide-by-zero.rs

// https://github.com/rust-lang/rust/issues/114814

fn main() {
let _ = 1 / &0;
}
8 changes: 8 additions & 0 deletions tests/ui/numbers-arithmetic/location-mod-assign-by-zero.rs
@@ -0,0 +1,8 @@
// run-fail
// ignore-wasm32
// error-pattern:location-mod-assign-by-zero.rs

fn main() {
let mut a = 1;
a %= &0;
}
7 changes: 7 additions & 0 deletions tests/ui/numbers-arithmetic/location-mod-by-zero.rs
@@ -0,0 +1,7 @@
// run-fail
// ignore-wasm32
// error-pattern:location-mod-by-zero.rs

fn main() {
let _ = 1 % &0;
}
8 changes: 8 additions & 0 deletions tests/ui/numbers-arithmetic/location-mul-assign-overflow.rs
@@ -0,0 +1,8 @@
// run-fail
// ignore-wasm32
// error-pattern:location-mul-assign-overflow.rs

fn main() {
let mut a: u8 = 255;
a *= &2;
}
7 changes: 7 additions & 0 deletions tests/ui/numbers-arithmetic/location-mul-overflow.rs
@@ -0,0 +1,7 @@
// run-fail
// ignore-wasm32
// error-pattern:location-mul-overflow.rs

fn main() {
let _: u8 = 255 * &2;
}
8 changes: 8 additions & 0 deletions tests/ui/numbers-arithmetic/location-sub-assign-overflow.rs
@@ -0,0 +1,8 @@
// run-fail
// ignore-wasm32
// error-pattern:location-sub-assign-overflow.rs

fn main() {
let mut a: u8 = 0;
a -= &1;
}
7 changes: 7 additions & 0 deletions tests/ui/numbers-arithmetic/location-sub-overflow.rs
@@ -0,0 +1,7 @@
// run-fail
// ignore-wasm32
// error-pattern:location-sub-overflow.rs

fn main() {
let _: u8 = 0 - &1;
}

0 comments on commit fc87d6e

Please sign in to comment.