lint-overflowing-ops: unify cases and remove redundancy

This commit is contained in:
Ralf Jung 2024-02-23 12:28:00 +01:00
parent dda102c190
commit 9a2d550050
4 changed files with 1688 additions and 1173 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -184,6 +184,9 @@ fn main() {
let _n = 1usize - 5; //~ ERROR: arithmetic operation will overflow
let _n = &(1usize - 5); //~ ERROR: arithmetic operation will overflow
let _n = -i8::MIN; //~ ERROR this arithmetic operation will overflow
let _n = &(-i8::MIN); //~ ERROR this arithmetic operation will overflow
// Multiplication
let _n = u8::MAX * 5; //~ ERROR: arithmetic operation will overflow
@ -201,6 +204,9 @@ fn main() {
let _n = u128::MAX * 5; //~ ERROR: arithmetic operation will overflow
let _n = &(u128::MAX * 5); //~ ERROR: arithmetic operation will overflow
let _n = usize::MAX * 5; //~ ERROR: arithmetic operation will overflow
let _n = &(usize::MAX * 5); //~ ERROR: arithmetic operation will overflow
let _n = i8::MAX * i8::MAX; //~ ERROR: arithmetic operation will overflow
let _n = &(i8::MAX * i8::MAX); //~ ERROR: arithmetic operation will overflow
@ -219,12 +225,6 @@ fn main() {
let _n = isize::MAX * 5; //~ ERROR: arithmetic operation will overflow
let _n = &(isize::MAX * 5); //~ ERROR: arithmetic operation will overflow
let _n = usize::MAX * 5; //~ ERROR: arithmetic operation will overflow
let _n = &(usize::MAX * 5); //~ ERROR: arithmetic operation will overflow
let _n = -i8::MIN; //~ ERROR this arithmetic operation will overflow
let _n = &(-i8::MIN); //~ ERROR this arithmetic operation will overflow
// Division
let _n = 1u8 / 0; //~ ERROR: this operation will panic at runtime
@ -242,26 +242,44 @@ fn main() {
let _n = 1u128 / 0; //~ ERROR: this operation will panic at runtime
let _n = &(1u128 / 0); //~ ERROR: this operation will panic at runtime
let _n = 1usize / 0; //~ ERROR: this operation will panic at runtime
let _n = &(1usize / 0); //~ ERROR: this operation will panic at runtime
let _n = 1i8 / 0; //~ ERROR: this operation will panic at runtime
let _n = &(1i8 / 0); //~ ERROR: this operation will panic at runtime
let _n = i8::MIN / -1; //~ ERROR: this operation will panic at runtime
let _n = &(i8::MIN / -1); //~ ERROR: this operation will panic at runtime
//~^ERROR: evaluation of constant value failed
let _n = 1i16 / 0; //~ ERROR: this operation will panic at runtime
let _n = &(1i16 / 0); //~ ERROR: this operation will panic at runtime
let _n = i16::MIN / -1; //~ ERROR: this operation will panic at runtime
let _n = &(i16::MIN / -1); //~ ERROR: this operation will panic at runtime
//~^ERROR: evaluation of constant value failed
let _n = 1i32 / 0; //~ ERROR: this operation will panic at runtime
let _n = &(1i32 / 0); //~ ERROR: this operation will panic at runtime
let _n = i32::MIN / -1; //~ ERROR: this operation will panic at runtime
let _n = &(i32::MIN / -1); //~ ERROR: this operation will panic at runtime
//~^ERROR: evaluation of constant value failed
let _n = 1i64 / 0; //~ ERROR: this operation will panic at runtime
let _n = &(1i64 / 0); //~ ERROR: this operation will panic at runtime
let _n = i64::MIN / -1; //~ ERROR: this operation will panic at runtime
let _n = &(i64::MIN / -1); //~ ERROR: this operation will panic at runtime
//~^ERROR: evaluation of constant value failed
let _n = 1i128 / 0; //~ ERROR: this operation will panic at runtime
let _n = &(1i128 / 0); //~ ERROR: this operation will panic at runtime
let _n = i128::MIN / -1; //~ ERROR: this operation will panic at runtime
let _n = &(i128::MIN / -1); //~ ERROR: this operation will panic at runtime
//~^ERROR: evaluation of constant value failed
let _n = 1isize / 0; //~ ERROR: this operation will panic at runtime
let _n = &(1isize / 0); //~ ERROR: this operation will panic at runtime
let _n = 1usize / 0; //~ ERROR: this operation will panic at runtime
let _n = &(1usize / 0); //~ ERROR: this operation will panic at runtime
let _n = isize::MIN / -1; //~ ERROR: this operation will panic at runtime
let _n = &(isize::MIN / -1); //~ ERROR: this operation will panic at runtime
//~^ERROR: evaluation of constant value failed
// Modulus
@ -280,80 +298,46 @@ fn main() {
let _n = 1u128 % 0; //~ ERROR: this operation will panic at runtime
let _n = &(1u128 % 0); //~ ERROR: this operation will panic at runtime
let _n = 1i8 % 0; //~ ERROR: this operation will panic at runtime
let _n = &(1i8 % 0); //~ ERROR: this operation will panic at runtime
let _n = 1i16 % 0; //~ ERROR: this operation will panic at runtime
let _n = &(1i16 % 0); //~ ERROR: this operation will panic at runtime
let _n = 1i32 % 0; //~ ERROR: this operation will panic at runtime
let _n = &(1i32 % 0); //~ ERROR: this operation will panic at runtime
let _n = 1i64 % 0; //~ ERROR: this operation will panic at runtime
let _n = &(1i64 % 0); //~ ERROR: this operation will panic at runtime
let _n = 1i128 % 0; //~ ERROR: this operation will panic at runtime
let _n = &(1i128 % 0); //~ ERROR: this operation will panic at runtime
let _n = 1isize % 0; //~ ERROR: this operation will panic at runtime
let _n = &(1isize % 0); //~ ERROR: this operation will panic at runtime
let _n = 1usize % 0; //~ ERROR: this operation will panic at runtime
let _n = &(1usize % 0); //~ ERROR: this operation will panic at runtime
let _n = 1i8 % 0; //~ ERROR: this operation will panic at runtime
let _n = &(1i8 % 0); //~ ERROR: this operation will panic at runtime
let _n = i8::MIN % -1; //~ ERROR: this operation will panic at runtime
let _n = &(i8::MIN % -1); //~ ERROR: this operation will panic at runtime
//~^ERROR: evaluation of constant value failed
let _n = 1i16 % 0; //~ ERROR: this operation will panic at runtime
let _n = &(1i16 % 0); //~ ERROR: this operation will panic at runtime
let _n = i16::MIN % -1; //~ ERROR: this operation will panic at runtime
let _n = &(i16::MIN % -1); //~ ERROR: this operation will panic at runtime
//~^ERROR: evaluation of constant value failed
let _n = 1i32 % 0; //~ ERROR: this operation will panic at runtime
let _n = &(1i32 % 0); //~ ERROR: this operation will panic at runtime
let _n = i32::MIN % -1; //~ ERROR: this operation will panic at runtime
let _n = &(i32::MIN % -1); //~ ERROR: this operation will panic at runtime
//~^ERROR: evaluation of constant value failed
let _n = 1i64 % 0; //~ ERROR: this operation will panic at runtime
let _n = &(1i64 % 0); //~ ERROR: this operation will panic at runtime
let _n = i64::MIN % -1; //~ ERROR: this operation will panic at runtime
let _n = &(i64::MIN % -1); //~ ERROR: this operation will panic at runtime
//~^ERROR: evaluation of constant value failed
let _n = 1i128 % 0; //~ ERROR: this operation will panic at runtime
let _n = &(1i128 % 0); //~ ERROR: this operation will panic at runtime
let _n = i128::MIN % -1; //~ ERROR: this operation will panic at runtime
let _n = &(i128::MIN % -1); //~ ERROR: this operation will panic at runtime
//~^ERROR: evaluation of constant value failed
let _n = 1isize % 0; //~ ERROR: this operation will panic at runtime
let _n = &(1isize % 0); //~ ERROR: this operation will panic at runtime
let _n = isize::MIN % -1; //~ ERROR: this operation will panic at runtime
let _n = &(isize::MIN % -1); //~ ERROR: this operation will panic at runtime
//~^ERROR: evaluation of constant value failed
// Out of bounds access
let _n = [1, 2, 3][4]; //~ ERROR: this operation will panic at runtime
let _n = &([1, 2, 3][4]); //~ ERROR: this operation will panic at runtime
// issue-8460-const
assert!(thread::spawn(move|| { isize::MIN / -1; }).join().is_err());
//~^ ERROR operation will panic
assert!(thread::spawn(move|| { i8::MIN / -1; }).join().is_err());
//~^ ERROR operation will panic
assert!(thread::spawn(move|| { i16::MIN / -1; }).join().is_err());
//~^ ERROR operation will panic
assert!(thread::spawn(move|| { i32::MIN / -1; }).join().is_err());
//~^ ERROR operation will panic
assert!(thread::spawn(move|| { i64::MIN / -1; }).join().is_err());
//~^ ERROR operation will panic
assert!(thread::spawn(move|| { i128::MIN / -1; }).join().is_err());
//~^ ERROR operation will panic
assert!(thread::spawn(move|| { 1isize / 0; }).join().is_err());
//~^ ERROR operation will panic
assert!(thread::spawn(move|| { 1i8 / 0; }).join().is_err());
//~^ ERROR operation will panic
assert!(thread::spawn(move|| { 1i16 / 0; }).join().is_err());
//~^ ERROR operation will panic
assert!(thread::spawn(move|| { 1i32 / 0; }).join().is_err());
//~^ ERROR operation will panic
assert!(thread::spawn(move|| { 1i64 / 0; }).join().is_err());
//~^ ERROR operation will panic
assert!(thread::spawn(move|| { 1i128 / 0; }).join().is_err());
//~^ ERROR operation will panic
assert!(thread::spawn(move|| { isize::MIN % -1; }).join().is_err());
//~^ ERROR operation will panic
assert!(thread::spawn(move|| { i8::MIN % -1; }).join().is_err());
//~^ ERROR operation will panic
assert!(thread::spawn(move|| { i16::MIN % -1; }).join().is_err());
//~^ ERROR operation will panic
assert!(thread::spawn(move|| { i32::MIN % -1; }).join().is_err());
//~^ ERROR operation will panic
assert!(thread::spawn(move|| { i64::MIN % -1; }).join().is_err());
//~^ ERROR operation will panic
assert!(thread::spawn(move|| { i128::MIN % -1; }).join().is_err());
//~^ ERROR operation will panic
assert!(thread::spawn(move|| { 1isize % 0; }).join().is_err());
//~^ ERROR operation will panic
assert!(thread::spawn(move|| { 1i8 % 0; }).join().is_err());
//~^ ERROR operation will panic
assert!(thread::spawn(move|| { 1i16 % 0; }).join().is_err());
//~^ ERROR operation will panic
assert!(thread::spawn(move|| { 1i32 % 0; }).join().is_err());
//~^ ERROR operation will panic
assert!(thread::spawn(move|| { 1i64 % 0; }).join().is_err());
//~^ ERROR operation will panic
assert!(thread::spawn(move|| { 1i128 % 0; }).join().is_err());
//~^ ERROR operation will panic
}