Skip to content

Move as many tests from tests/ui/numbers-arithmetic to tests/ui/lint as possible #121432

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
538 changes: 368 additions & 170 deletions tests/ui/lint/lint-overflowing-ops.noopt.stderr

Large diffs are not rendered by default.

538 changes: 368 additions & 170 deletions tests/ui/lint/lint-overflowing-ops.opt.stderr

Large diffs are not rendered by default.

538 changes: 368 additions & 170 deletions tests/ui/lint/lint-overflowing-ops.opt_with_overflow_checks.stderr

Large diffs are not rendered by default.

65 changes: 65 additions & 0 deletions tests/ui/lint/lint-overflowing-ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const BITS: usize = 32;
#[cfg(target_pointer_width = "64")]
const BITS: usize = 64;

use std::thread;

fn main() {
// Shift left
let _n = 1u8 << 8; //~ ERROR: arithmetic operation will overflow
Expand Down Expand Up @@ -59,8 +61,15 @@ fn main() {
let _n = 1_usize << BITS; //~ ERROR: arithmetic operation will overflow
let _n = &(1_usize << BITS); //~ ERROR: arithmetic operation will overflow

let _n = 1 << -1; //~ ERROR: arithmetic operation will overflow
let _n = &(1 << -1); //~ ERROR: arithmetic operation will overflow

// Shift right

let _n = -1_i64 >> 64; //~ ERROR: arithmetic operation will overflow
let _n = -1_i32 >> 32; //~ ERROR: arithmetic operation will overflow
let _n = -1_i32 >> -1; //~ ERROR: arithmetic operation will overflow

let _n = 1u8 >> 8; //~ ERROR: arithmetic operation will overflow
let _n = &(1u8 >> 8); //~ ERROR: arithmetic operation will overflow

Expand Down Expand Up @@ -97,6 +106,8 @@ fn main() {
let _n = 1_usize >> BITS; //~ ERROR: arithmetic operation will overflow
let _n = &(1_usize >> BITS); //~ ERROR: arithmetic operation will overflow

let _n = 1i64 >> [64][0]; //~ ERROR: arithmetic operation will overflow
let _n = &(1i64 >> [64][0]); //~ ERROR: arithmetic operation will overflow

// Addition
let _n = 1u8 + u8::MAX; //~ ERROR: arithmetic operation will overflow
Expand Down Expand Up @@ -211,6 +222,9 @@ fn main() {
let _n = usize::MAX * 5; //~ ERROR: arithmetic operation will overflow
let _n = &(usize::MAX * 5); //~ ERROR: arithmetic operation will overflow

let _x = -i8::MIN; //~ ERROR this arithmetic operation will overflow
let _x = &(-i8::MIN); //~ ERROR this arithmetic operation will overflow


// Division
let _n = 1u8 / 0; //~ ERROR: this operation will panic at runtime
Expand Down Expand Up @@ -291,4 +305,55 @@ fn main() {
// 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
}
148 changes: 0 additions & 148 deletions tests/ui/numbers-arithmetic/issue-8460-const.noopt.stderr

This file was deleted.

148 changes: 0 additions & 148 deletions tests/ui/numbers-arithmetic/issue-8460-const.opt.stderr

This file was deleted.

Loading