Auto merge of #114841 - bvanjoi:fix-114814, r=cuviper

add track_caller for arith ops

Fixes #114814

`#[track_caller]` is works, r? `@scottmcm`
This commit is contained in:
bors 2023-11-29 00:47:25 +00:00
commit b1e56deada
16 changed files with 95 additions and 4 deletions

View file

@ -31,6 +31,7 @@ impl<'a> $imp<$u> for &'a $t {
type Output = <$t as $imp<$u>>::Output;
#[inline]
#[track_caller]
fn $method(self, other: $u) -> <$t as $imp<$u>>::Output {
$imp::$method(*self, other)
}
@ -41,6 +42,7 @@ impl $imp<&$u> for $t {
type Output = <$t as $imp<$u>>::Output;
#[inline]
#[track_caller]
fn $method(self, other: &$u) -> <$t as $imp<$u>>::Output {
$imp::$method(self, *other)
}
@ -51,6 +53,7 @@ impl $imp<&$u> for &$t {
type Output = <$t as $imp<$u>>::Output;
#[inline]
#[track_caller]
fn $method(self, other: &$u) -> <$t as $imp<$u>>::Output {
$imp::$method(*self, *other)
}
@ -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);
}

View file

@ -98,6 +98,7 @@ impl Add for $t {
type Output = $t;
#[inline]
#[track_caller]
#[rustc_inherit_overflow_checks]
fn add(self, other: $t) -> $t { self + other }
}
@ -206,6 +207,7 @@ impl Sub for $t {
type Output = $t;
#[inline]
#[track_caller]
#[rustc_inherit_overflow_checks]
fn sub(self, other: $t) -> $t { self - other }
}
@ -335,6 +337,7 @@ impl Mul for $t {
type Output = $t;
#[inline]
#[track_caller]
#[rustc_inherit_overflow_checks]
fn mul(self, other: $t) -> $t { self * other }
}
@ -474,6 +477,7 @@ impl Div for $t {
type Output = $t;
#[inline]
#[track_caller]
fn div(self, other: $t) -> $t { self / other }
}
@ -575,6 +579,7 @@ impl Rem for $t {
type Output = $t;
#[inline]
#[track_caller]
fn rem(self, other: $t) -> $t { self % other }
}
@ -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 }
}
@ -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 }
}
@ -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 }
}
@ -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 }
}
@ -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 }
}

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -0,0 +1,8 @@
// run-fail
// ignore-wasm32
// error-pattern:location-add-assign-overflow.rs
fn main() {
let mut a: u8 = 255;
a += &1;
}

View file

@ -0,0 +1,7 @@
// run-fail
// ignore-wasm32
// error-pattern:location-add-overflow.rs
fn main() {
let _: u8 = 255 + &1;
}

View file

@ -0,0 +1,8 @@
// run-fail
// ignore-wasm32
// error-pattern:location-divide-assign-by-zero.rs
fn main() {
let mut a = 1;
a /= &0;
}

View file

@ -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;
}

View file

@ -0,0 +1,8 @@
// run-fail
// ignore-wasm32
// error-pattern:location-mod-assign-by-zero.rs
fn main() {
let mut a = 1;
a %= &0;
}

View file

@ -0,0 +1,7 @@
// run-fail
// ignore-wasm32
// error-pattern:location-mod-by-zero.rs
fn main() {
let _ = 1 % &0;
}

View file

@ -0,0 +1,8 @@
// run-fail
// ignore-wasm32
// error-pattern:location-mul-assign-overflow.rs
fn main() {
let mut a: u8 = 255;
a *= &2;
}

View file

@ -0,0 +1,7 @@
// run-fail
// ignore-wasm32
// error-pattern:location-mul-overflow.rs
fn main() {
let _: u8 = 255 * &2;
}

View file

@ -0,0 +1,8 @@
// run-fail
// ignore-wasm32
// error-pattern:location-sub-assign-overflow.rs
fn main() {
let mut a: u8 = 0;
a -= &1;
}

View file

@ -0,0 +1,7 @@
// run-fail
// ignore-wasm32
// error-pattern:location-sub-overflow.rs
fn main() {
let _: u8 = 0 - &1;
}