@@ -21,6 +21,8 @@ const BITS: usize = 32;
21
21
#[ cfg( target_pointer_width = "64" ) ]
22
22
const BITS : usize = 64 ;
23
23
24
+ use std:: thread;
25
+
24
26
fn main ( ) {
25
27
// Shift left
26
28
let _n = 1u8 << 8 ; //~ ERROR: arithmetic operation will overflow
@@ -59,8 +61,15 @@ fn main() {
59
61
let _n = 1_usize << BITS ; //~ ERROR: arithmetic operation will overflow
60
62
let _n = & ( 1_usize << BITS ) ; //~ ERROR: arithmetic operation will overflow
61
63
64
+ let _n = 1 << -1 ; //~ ERROR: arithmetic operation will overflow
65
+ let _n = & ( 1 << -1 ) ; //~ ERROR: arithmetic operation will overflow
62
66
63
67
// 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
+
64
73
let _n = 1u8 >> 8 ; //~ ERROR: arithmetic operation will overflow
65
74
let _n = & ( 1u8 >> 8 ) ; //~ ERROR: arithmetic operation will overflow
66
75
@@ -97,6 +106,8 @@ fn main() {
97
106
let _n = 1_usize >> BITS ; //~ ERROR: arithmetic operation will overflow
98
107
let _n = & ( 1_usize >> BITS ) ; //~ ERROR: arithmetic operation will overflow
99
108
109
+ let _n = 1i64 >> [ 64 ] [ 0 ] ; //~ ERROR: arithmetic operation will overflow
110
+ let _n = & ( 1i64 >> [ 64 ] [ 0 ] ) ; //~ ERROR: arithmetic operation will overflow
100
111
101
112
// Addition
102
113
let _n = 1u8 + u8:: MAX ; //~ ERROR: arithmetic operation will overflow
@@ -211,6 +222,9 @@ fn main() {
211
222
let _n = usize:: MAX * 5 ; //~ ERROR: arithmetic operation will overflow
212
223
let _n = & ( usize:: MAX * 5 ) ; //~ ERROR: arithmetic operation will overflow
213
224
225
+ let _x = -i8:: MIN ; //~ ERROR this arithmetic operation will overflow
226
+ let _x = & ( -i8:: MIN ) ; //~ ERROR this arithmetic operation will overflow
227
+
214
228
215
229
// Division
216
230
let _n = 1u8 / 0 ; //~ ERROR: this operation will panic at runtime
@@ -291,4 +305,55 @@ fn main() {
291
305
// Out of bounds access
292
306
let _n = [ 1 , 2 , 3 ] [ 4 ] ; //~ ERROR: this operation will panic at runtime
293
307
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
294
359
}
0 commit comments