Rollup merge of #121510 - RalfJung:lint-overflowing-ops, r=oli-obk

lint-overflowing-ops: unify cases and remove redundancy

Follow-up to https://github.com/rust-lang/rust/pull/121432
r? `@oli-obk`
This commit is contained in:
Matthias Krüger 2024-02-23 17:02:06 +01:00 committed by GitHub
commit 06e54f8d49
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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 = &(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 // Multiplication
let _n = u8::MAX * 5; //~ ERROR: arithmetic operation will overflow 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 = &(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
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 = &(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 // Division
let _n = 1u8 / 0; //~ ERROR: this operation will panic at runtime 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 = &(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 = &(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 = &(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 = &(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 = &(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 = &(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 = &(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 = 1usize / 0; //~ ERROR: this operation will panic at runtime let _n = &(isize::MIN / -1); //~ ERROR: this operation will panic at runtime
let _n = &(1usize / 0); //~ ERROR: this operation will panic at runtime //~^ERROR: evaluation of constant value failed
// Modulus // 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 = &(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 = &(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 // 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
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
} }