Skip to content

Commit 03f095f

Browse files
committed
consolidate tests
1 parent d8b0069 commit 03f095f

23 files changed

+1169
-1184
lines changed

Diff for: tests/ui/lint/lint-overflowing-ops.noopt.stderr

+368-170
Large diffs are not rendered by default.

Diff for: tests/ui/lint/lint-overflowing-ops.opt.stderr

+368-170
Large diffs are not rendered by default.

Diff for: tests/ui/lint/lint-overflowing-ops.opt_with_overflow_checks.stderr

+368-170
Large diffs are not rendered by default.

Diff for: tests/ui/lint/lint-overflowing-ops.rs

+65
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ const BITS: usize = 32;
2121
#[cfg(target_pointer_width = "64")]
2222
const BITS: usize = 64;
2323

24+
use std::thread;
25+
2426
fn main() {
2527
// Shift left
2628
let _n = 1u8 << 8; //~ ERROR: arithmetic operation will overflow
@@ -59,8 +61,15 @@ fn main() {
5961
let _n = 1_usize << BITS; //~ ERROR: arithmetic operation will overflow
6062
let _n = &(1_usize << BITS); //~ ERROR: arithmetic operation will overflow
6163

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

6367
// Shift right
68+
69+
let _n = -1_i64 >> 64; //~ ERROR: arithmetic operation will overflow
70+
let _n = -1_i32 >> 32; //~ ERROR: arithmetic operation will overflow
71+
let _n = -1_i32 >> -1; //~ ERROR: arithmetic operation will overflow
72+
6473
let _n = 1u8 >> 8; //~ ERROR: arithmetic operation will overflow
6574
let _n = &(1u8 >> 8); //~ ERROR: arithmetic operation will overflow
6675

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

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

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

225+
let _x = -i8::MIN; //~ ERROR this arithmetic operation will overflow
226+
let _x = &(-i8::MIN); //~ ERROR this arithmetic operation will overflow
227+
214228

215229
// Division
216230
let _n = 1u8 / 0; //~ ERROR: this operation will panic at runtime
@@ -291,4 +305,55 @@ fn main() {
291305
// Out of bounds access
292306
let _n = [1, 2, 3][4]; //~ ERROR: this operation will panic at runtime
293307
let _n = &([1, 2, 3][4]); //~ ERROR: this operation will panic at runtime
308+
309+
310+
// issue-8460-const
311+
assert!(thread::spawn(move|| { isize::MIN / -1; }).join().is_err());
312+
//~^ ERROR operation will panic
313+
assert!(thread::spawn(move|| { i8::MIN / -1; }).join().is_err());
314+
//~^ ERROR operation will panic
315+
assert!(thread::spawn(move|| { i16::MIN / -1; }).join().is_err());
316+
//~^ ERROR operation will panic
317+
assert!(thread::spawn(move|| { i32::MIN / -1; }).join().is_err());
318+
//~^ ERROR operation will panic
319+
assert!(thread::spawn(move|| { i64::MIN / -1; }).join().is_err());
320+
//~^ ERROR operation will panic
321+
assert!(thread::spawn(move|| { i128::MIN / -1; }).join().is_err());
322+
//~^ ERROR operation will panic
323+
assert!(thread::spawn(move|| { 1isize / 0; }).join().is_err());
324+
//~^ ERROR operation will panic
325+
assert!(thread::spawn(move|| { 1i8 / 0; }).join().is_err());
326+
//~^ ERROR operation will panic
327+
assert!(thread::spawn(move|| { 1i16 / 0; }).join().is_err());
328+
//~^ ERROR operation will panic
329+
assert!(thread::spawn(move|| { 1i32 / 0; }).join().is_err());
330+
//~^ ERROR operation will panic
331+
assert!(thread::spawn(move|| { 1i64 / 0; }).join().is_err());
332+
//~^ ERROR operation will panic
333+
assert!(thread::spawn(move|| { 1i128 / 0; }).join().is_err());
334+
//~^ ERROR operation will panic
335+
assert!(thread::spawn(move|| { isize::MIN % -1; }).join().is_err());
336+
//~^ ERROR operation will panic
337+
assert!(thread::spawn(move|| { i8::MIN % -1; }).join().is_err());
338+
//~^ ERROR operation will panic
339+
assert!(thread::spawn(move|| { i16::MIN % -1; }).join().is_err());
340+
//~^ ERROR operation will panic
341+
assert!(thread::spawn(move|| { i32::MIN % -1; }).join().is_err());
342+
//~^ ERROR operation will panic
343+
assert!(thread::spawn(move|| { i64::MIN % -1; }).join().is_err());
344+
//~^ ERROR operation will panic
345+
assert!(thread::spawn(move|| { i128::MIN % -1; }).join().is_err());
346+
//~^ ERROR operation will panic
347+
assert!(thread::spawn(move|| { 1isize % 0; }).join().is_err());
348+
//~^ ERROR operation will panic
349+
assert!(thread::spawn(move|| { 1i8 % 0; }).join().is_err());
350+
//~^ ERROR operation will panic
351+
assert!(thread::spawn(move|| { 1i16 % 0; }).join().is_err());
352+
//~^ ERROR operation will panic
353+
assert!(thread::spawn(move|| { 1i32 % 0; }).join().is_err());
354+
//~^ ERROR operation will panic
355+
assert!(thread::spawn(move|| { 1i64 % 0; }).join().is_err());
356+
//~^ ERROR operation will panic
357+
assert!(thread::spawn(move|| { 1i128 % 0; }).join().is_err());
358+
//~^ ERROR operation will panic
294359
}

Diff for: tests/ui/numbers-arithmetic/issue-8460-const.noopt.stderr

-148
This file was deleted.

Diff for: tests/ui/numbers-arithmetic/issue-8460-const.opt.stderr

-148
This file was deleted.

0 commit comments

Comments
 (0)