[arithmetic-side-effects] Finish non-overflowing ops
This commit is contained in:
parent
56a8ef4dbe
commit
dba5adae6e
3 changed files with 127 additions and 82 deletions
|
|
@ -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;
|
||||
pub fn overflowing_runtime_ops() {
|
||||
let mut _n = i32::MAX;
|
||||
|
||||
let mut _b = 1; _b = _b + 1;
|
||||
// Assign
|
||||
_n += 1;
|
||||
_n -= 1;
|
||||
_n /= 0;
|
||||
_n %= 0;
|
||||
_n *= 2;
|
||||
|
||||
let mut _c = 1; _c = 1 + _c;
|
||||
|
||||
let mut _a = 1;
|
||||
_a += 1;
|
||||
_a -= 1;
|
||||
_a /= 0;
|
||||
_a %= 0;
|
||||
_a *= 2;
|
||||
_a *= 3;
|
||||
// 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() {}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
| ^^^^^^
|
||||
|
||||
error: arithmetic detected
|
||||
--> $DIR/arithmetic_side_effects.rs:62:26
|
||||
|
|
||||
LL | let mut _c = 1; _c = 1 + _c;
|
||||
| ^^^^^^
|
||||
|
||||
error: arithmetic detected
|
||||
--> $DIR/arithmetic_side_effects.rs:65:5
|
||||
|
|
||||
LL | _a += 1;
|
||||
LL | _n -= 1;
|
||||
| ^^^^^^^
|
||||
|
||||
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:82:5
|
||||
|
|
||||
LL | _a -= 1;
|
||||
LL | _n /= 0;
|
||||
| ^^^^^^^
|
||||
|
||||
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:83:5
|
||||
|
|
||||
LL | _a /= 0;
|
||||
LL | _n %= 0;
|
||||
| ^^^^^^^
|
||||
|
||||
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:84:5
|
||||
|
|
||||
LL | _a %= 0;
|
||||
LL | _n *= 2;
|
||||
| ^^^^^^^
|
||||
|
||||
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:87: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:88:10
|
||||
|
|
||||
LL | _a *= 3;
|
||||
| ^^^^^^^
|
||||
LL | _n = 1 + _n;
|
||||
| ^^^^^^
|
||||
|
||||
error: aborting due to 9 previous errors
|
||||
error: arithmetic operation that can potentially result in unexpected side-effects
|
||||
--> $DIR/arithmetic_side_effects.rs:89:10
|
||||
|
|
||||
LL | _n = _n - 1;
|
||||
| ^^^^^^
|
||||
|
||||
error: arithmetic operation that can potentially result in unexpected side-effects
|
||||
--> $DIR/arithmetic_side_effects.rs:90:10
|
||||
|
|
||||
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 13 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue