Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9a2d550

Browse files
committedFeb 23, 2024
lint-overflowing-ops: unify cases and remove redundancy
1 parent dda102c commit 9a2d550

File tree

4 files changed

+1191
-676
lines changed

4 files changed

+1191
-676
lines changed
 

‎tests/ui/lint/lint-overflowing-ops.noopt.stderr

Lines changed: 350 additions & 205 deletions
Large diffs are not rendered by default.

‎tests/ui/lint/lint-overflowing-ops.opt.stderr

Lines changed: 443 additions & 202 deletions
Large diffs are not rendered by default.

‎tests/ui/lint/lint-overflowing-ops.opt_with_overflow_checks.stderr

Lines changed: 350 additions & 205 deletions
Large diffs are not rendered by default.

‎tests/ui/lint/lint-overflowing-ops.rs

Lines changed: 48 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ fn main() {
184184
let _n = 1usize - 5; //~ ERROR: arithmetic operation will overflow
185185
let _n = &(1usize - 5); //~ ERROR: arithmetic operation will overflow
186186

187+
let _n = -i8::MIN; //~ ERROR this arithmetic operation will overflow
188+
let _n = &(-i8::MIN); //~ ERROR this arithmetic operation will overflow
189+
187190

188191
// Multiplication
189192
let _n = u8::MAX * 5; //~ ERROR: arithmetic operation will overflow
@@ -201,6 +204,9 @@ fn main() {
201204
let _n = u128::MAX * 5; //~ ERROR: arithmetic operation will overflow
202205
let _n = &(u128::MAX * 5); //~ ERROR: arithmetic operation will overflow
203206

207+
let _n = usize::MAX * 5; //~ ERROR: arithmetic operation will overflow
208+
let _n = &(usize::MAX * 5); //~ ERROR: arithmetic operation will overflow
209+
204210
let _n = i8::MAX * i8::MAX; //~ ERROR: arithmetic operation will overflow
205211
let _n = &(i8::MAX * i8::MAX); //~ ERROR: arithmetic operation will overflow
206212

@@ -219,12 +225,6 @@ fn main() {
219225
let _n = isize::MAX * 5; //~ ERROR: arithmetic operation will overflow
220226
let _n = &(isize::MAX * 5); //~ ERROR: arithmetic operation will overflow
221227

222-
let _n = usize::MAX * 5; //~ ERROR: arithmetic operation will overflow
223-
let _n = &(usize::MAX * 5); //~ ERROR: arithmetic operation will overflow
224-
225-
let _n = -i8::MIN; //~ ERROR this arithmetic operation will overflow
226-
let _n = &(-i8::MIN); //~ ERROR this arithmetic operation will overflow
227-
228228

229229
// Division
230230
let _n = 1u8 / 0; //~ ERROR: this operation will panic at runtime
@@ -242,26 +242,44 @@ fn main() {
242242
let _n = 1u128 / 0; //~ ERROR: this operation will panic at runtime
243243
let _n = &(1u128 / 0); //~ ERROR: this operation will panic at runtime
244244

245+
let _n = 1usize / 0; //~ ERROR: this operation will panic at runtime
246+
let _n = &(1usize / 0); //~ ERROR: this operation will panic at runtime
247+
245248
let _n = 1i8 / 0; //~ ERROR: this operation will panic at runtime
246249
let _n = &(1i8 / 0); //~ ERROR: this operation will panic at runtime
250+
let _n = i8::MIN / -1; //~ ERROR: this operation will panic at runtime
251+
let _n = &(i8::MIN / -1); //~ ERROR: this operation will panic at runtime
252+
//~^ERROR: evaluation of constant value failed
247253

248254
let _n = 1i16 / 0; //~ ERROR: this operation will panic at runtime
249255
let _n = &(1i16 / 0); //~ ERROR: this operation will panic at runtime
256+
let _n = i16::MIN / -1; //~ ERROR: this operation will panic at runtime
257+
let _n = &(i16::MIN / -1); //~ ERROR: this operation will panic at runtime
258+
//~^ERROR: evaluation of constant value failed
250259

251260
let _n = 1i32 / 0; //~ ERROR: this operation will panic at runtime
252261
let _n = &(1i32 / 0); //~ ERROR: this operation will panic at runtime
262+
let _n = i32::MIN / -1; //~ ERROR: this operation will panic at runtime
263+
let _n = &(i32::MIN / -1); //~ ERROR: this operation will panic at runtime
264+
//~^ERROR: evaluation of constant value failed
253265

254266
let _n = 1i64 / 0; //~ ERROR: this operation will panic at runtime
255267
let _n = &(1i64 / 0); //~ ERROR: this operation will panic at runtime
268+
let _n = i64::MIN / -1; //~ ERROR: this operation will panic at runtime
269+
let _n = &(i64::MIN / -1); //~ ERROR: this operation will panic at runtime
270+
//~^ERROR: evaluation of constant value failed
256271

257272
let _n = 1i128 / 0; //~ ERROR: this operation will panic at runtime
258273
let _n = &(1i128 / 0); //~ ERROR: this operation will panic at runtime
274+
let _n = i128::MIN / -1; //~ ERROR: this operation will panic at runtime
275+
let _n = &(i128::MIN / -1); //~ ERROR: this operation will panic at runtime
276+
//~^ERROR: evaluation of constant value failed
259277

260278
let _n = 1isize / 0; //~ ERROR: this operation will panic at runtime
261279
let _n = &(1isize / 0); //~ ERROR: this operation will panic at runtime
262-
263-
let _n = 1usize / 0; //~ ERROR: this operation will panic at runtime
264-
let _n = &(1usize / 0); //~ ERROR: this operation will panic at runtime
280+
let _n = isize::MIN / -1; //~ ERROR: this operation will panic at runtime
281+
let _n = &(isize::MIN / -1); //~ ERROR: this operation will panic at runtime
282+
//~^ERROR: evaluation of constant value failed
265283

266284

267285
// Modulus
@@ -280,80 +298,46 @@ fn main() {
280298
let _n = 1u128 % 0; //~ ERROR: this operation will panic at runtime
281299
let _n = &(1u128 % 0); //~ ERROR: this operation will panic at runtime
282300

301+
let _n = 1usize % 0; //~ ERROR: this operation will panic at runtime
302+
let _n = &(1usize % 0); //~ ERROR: this operation will panic at runtime
303+
283304
let _n = 1i8 % 0; //~ ERROR: this operation will panic at runtime
284305
let _n = &(1i8 % 0); //~ ERROR: this operation will panic at runtime
306+
let _n = i8::MIN % -1; //~ ERROR: this operation will panic at runtime
307+
let _n = &(i8::MIN % -1); //~ ERROR: this operation will panic at runtime
308+
//~^ERROR: evaluation of constant value failed
285309

286310
let _n = 1i16 % 0; //~ ERROR: this operation will panic at runtime
287311
let _n = &(1i16 % 0); //~ ERROR: this operation will panic at runtime
312+
let _n = i16::MIN % -1; //~ ERROR: this operation will panic at runtime
313+
let _n = &(i16::MIN % -1); //~ ERROR: this operation will panic at runtime
314+
//~^ERROR: evaluation of constant value failed
288315

289316
let _n = 1i32 % 0; //~ ERROR: this operation will panic at runtime
290317
let _n = &(1i32 % 0); //~ ERROR: this operation will panic at runtime
318+
let _n = i32::MIN % -1; //~ ERROR: this operation will panic at runtime
319+
let _n = &(i32::MIN % -1); //~ ERROR: this operation will panic at runtime
320+
//~^ERROR: evaluation of constant value failed
291321

292322
let _n = 1i64 % 0; //~ ERROR: this operation will panic at runtime
293323
let _n = &(1i64 % 0); //~ ERROR: this operation will panic at runtime
324+
let _n = i64::MIN % -1; //~ ERROR: this operation will panic at runtime
325+
let _n = &(i64::MIN % -1); //~ ERROR: this operation will panic at runtime
326+
//~^ERROR: evaluation of constant value failed
294327

295328
let _n = 1i128 % 0; //~ ERROR: this operation will panic at runtime
296329
let _n = &(1i128 % 0); //~ ERROR: this operation will panic at runtime
330+
let _n = i128::MIN % -1; //~ ERROR: this operation will panic at runtime
331+
let _n = &(i128::MIN % -1); //~ ERROR: this operation will panic at runtime
332+
//~^ERROR: evaluation of constant value failed
297333

298334
let _n = 1isize % 0; //~ ERROR: this operation will panic at runtime
299335
let _n = &(1isize % 0); //~ ERROR: this operation will panic at runtime
300-
301-
let _n = 1usize % 0; //~ ERROR: this operation will panic at runtime
302-
let _n = &(1usize % 0); //~ ERROR: this operation will panic at runtime
303-
336+
let _n = isize::MIN % -1; //~ ERROR: this operation will panic at runtime
337+
let _n = &(isize::MIN % -1); //~ ERROR: this operation will panic at runtime
338+
//~^ERROR: evaluation of constant value failed
304339

305340
// Out of bounds access
306341
let _n = [1, 2, 3][4]; //~ ERROR: this operation will panic at runtime
307342
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
359343
}

0 commit comments

Comments
 (0)
Please sign in to comment.