diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/arithmetic_side_effects.rs | 74 | ||||
| -rw-r--r-- | tests/ui/arithmetic_side_effects.stderr | 94 |
2 files changed, 108 insertions, 60 deletions
diff --git a/tests/ui/arithmetic_side_effects.rs b/tests/ui/arithmetic_side_effects.rs index a51c2514283..c07425be50a 100644 --- a/tests/ui/arithmetic_side_effects.rs +++ b/tests/ui/arithmetic_side_effects.rs @@ -1,7 +1,10 @@ #![allow( clippy::assign_op_pattern, - unconditional_panic, - clippy::unnecessary_owned_empty_strings + clippy::erasing_op, + clippy::identity_op, + clippy::unnecessary_owned_empty_strings, + arithmetic_overflow, + unconditional_panic )] #![feature(inline_const, saturating_int_impl)] #![warn(clippy::arithmetic_side_effects)] @@ -30,7 +33,7 @@ pub fn hard_coded_allowed() { } #[rustfmt::skip] -pub fn non_overflowing_ops() { +pub fn non_overflowing_const_ops() { const _: i32 = { let mut n = 1; n += 1; n }; let _ = const { let mut n = 1; n += 1; n }; @@ -41,33 +44,54 @@ pub fn non_overflowing_ops() { let _ = const { let mut n = 1; n = 1 + n; n }; const _: i32 = 1 + 1; - let _ = 1 + 1; let _ = const { 1 + 1 }; +} - let mut _a = 1; - _a += 0; - _a -= 0; - _a /= 99; - _a %= 99; - _a *= 0; - _a *= 1; +pub fn non_overflowing_runtime_ops() { + let mut _n = i32::MAX; + + // Assign + _n += 0; + _n -= 0; + _n /= 99; + _n %= 99; + _n *= 0; + _n *= 1; + + // Binary + _n = _n + 0; + _n = 0 + _n; + _n = _n - 0; + _n = 0 - _n; + _n = _n / 99; + _n = _n % 99; + _n = _n * 0; + _n = 0 * _n; + _n = _n * 1; + _n = 1 * _n; + _n = 23 + 85; } #[rustfmt::skip] -pub fn overflowing_ops() { - let mut _a = 1; _a += 1; - - let mut _b = 1; _b = _b + 1; - - let mut _c = 1; _c = 1 + _c; - - let mut _a = 1; - _a += 1; - _a -= 1; - _a /= 0; - _a %= 0; - _a *= 2; - _a *= 3; +pub fn overflowing_runtime_ops() { + let mut _n = i32::MAX; + + // Assign + _n += 1; + _n -= 1; + _n /= 0; + _n %= 0; + _n *= 2; + + // Binary + _n = _n + 1; + _n = 1 + _n; + _n = _n - 1; + _n = 1 - _n; + _n = _n / 0; + _n = _n % 0; + _n = _n * 2; + _n = 2 * _n; } fn main() {} diff --git a/tests/ui/arithmetic_side_effects.stderr b/tests/ui/arithmetic_side_effects.stderr index 6652a1f8ca8..2f953d26699 100644 --- a/tests/ui/arithmetic_side_effects.stderr +++ b/tests/ui/arithmetic_side_effects.stderr @@ -1,58 +1,82 @@ -error: arithmetic detected - --> $DIR/arithmetic_side_effects.rs:58:21 +error: arithmetic operation that can potentially result in unexpected side-effects + --> $DIR/arithmetic_side_effects.rs:80:5 | -LL | let mut _a = 1; _a += 1; - | ^^^^^^^ +LL | _n += 1; + | ^^^^^^^ | = note: `-D clippy::arithmetic-side-effects` implied by `-D warnings` -error: arithmetic detected - --> $DIR/arithmetic_side_effects.rs:60:26 +error: arithmetic operation that can potentially result in unexpected side-effects + --> $DIR/arithmetic_side_effects.rs:81:5 | -LL | let mut _b = 1; _b = _b + 1; - | ^^^^^^ +LL | _n -= 1; + | ^^^^^^^ -error: arithmetic detected - --> $DIR/arithmetic_side_effects.rs:62:26 +error: arithmetic operation that can potentially result in unexpected side-effects + --> $DIR/arithmetic_side_effects.rs:82:5 | -LL | let mut _c = 1; _c = 1 + _c; - | ^^^^^^ +LL | _n /= 0; + | ^^^^^^^ -error: arithmetic detected - --> $DIR/arithmetic_side_effects.rs:65:5 +error: arithmetic operation that can potentially result in unexpected side-effects + --> $DIR/arithmetic_side_effects.rs:83:5 | -LL | _a += 1; +LL | _n %= 0; | ^^^^^^^ -error: arithmetic detected - --> $DIR/arithmetic_side_effects.rs:66:5 +error: arithmetic operation that can potentially result in unexpected side-effects + --> $DIR/arithmetic_side_effects.rs:84:5 | -LL | _a -= 1; +LL | _n *= 2; | ^^^^^^^ -error: arithmetic detected - --> $DIR/arithmetic_side_effects.rs:67:5 +error: arithmetic operation that can potentially result in unexpected side-effects + --> $DIR/arithmetic_side_effects.rs:87:10 | -LL | _a /= 0; - | ^^^^^^^ +LL | _n = _n + 1; + | ^^^^^^ -error: arithmetic detected - --> $DIR/arithmetic_side_effects.rs:68:5 +error: arithmetic operation that can potentially result in unexpected side-effects + --> $DIR/arithmetic_side_effects.rs:88:10 | -LL | _a %= 0; - | ^^^^^^^ +LL | _n = 1 + _n; + | ^^^^^^ -error: arithmetic detected - --> $DIR/arithmetic_side_effects.rs:69:5 +error: arithmetic operation that can potentially result in unexpected side-effects + --> $DIR/arithmetic_side_effects.rs:89:10 | -LL | _a *= 2; - | ^^^^^^^ +LL | _n = _n - 1; + | ^^^^^^ -error: arithmetic detected - --> $DIR/arithmetic_side_effects.rs:70:5 +error: arithmetic operation that can potentially result in unexpected side-effects + --> $DIR/arithmetic_side_effects.rs:90:10 | -LL | _a *= 3; - | ^^^^^^^ +LL | _n = 1 - _n; + | ^^^^^^ + +error: arithmetic operation that can potentially result in unexpected side-effects + --> $DIR/arithmetic_side_effects.rs:91:10 + | +LL | _n = _n / 0; + | ^^^^^^ + +error: arithmetic operation that can potentially result in unexpected side-effects + --> $DIR/arithmetic_side_effects.rs:92:10 + | +LL | _n = _n % 0; + | ^^^^^^ + +error: arithmetic operation that can potentially result in unexpected side-effects + --> $DIR/arithmetic_side_effects.rs:93:10 + | +LL | _n = _n * 2; + | ^^^^^^ + +error: arithmetic operation that can potentially result in unexpected side-effects + --> $DIR/arithmetic_side_effects.rs:94:10 + | +LL | _n = 2 * _n; + | ^^^^^^ -error: aborting due to 9 previous errors +error: aborting due to 13 previous errors |
