Skip to content

Commit

Permalink
div/rem overflow tests: also test i128
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Feb 10, 2020
1 parent b434d7e commit 1ddb050
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 39 deletions.
12 changes: 11 additions & 1 deletion src/test/ui/issues/issue-8460-const.rs
Expand Up @@ -3,7 +3,7 @@

#![deny(const_err)]

use std::{isize, i8, i16, i32, i64};
use std::{isize, i8, i16, i32, i64, i128};
use std::thread;

fn main() {
Expand All @@ -22,6 +22,9 @@ fn main() {
assert!(thread::spawn(move|| { i64::MIN / -1; }).join().is_err());
//~^ ERROR attempt to divide with overflow
//~| ERROR this expression will panic at runtime
assert!(thread::spawn(move|| { i128::MIN / -1; }).join().is_err());
//~^ ERROR attempt to divide with overflow
//~| ERROR this expression will panic at runtime
assert!(thread::spawn(move|| { 1isize / 0; }).join().is_err());
//~^ ERROR attempt to divide by zero
assert!(thread::spawn(move|| { 1i8 / 0; }).join().is_err());
Expand All @@ -32,6 +35,8 @@ fn main() {
//~^ ERROR attempt to divide by zero
assert!(thread::spawn(move|| { 1i64 / 0; }).join().is_err());
//~^ ERROR attempt to divide by zero
assert!(thread::spawn(move|| { 1i128 / 0; }).join().is_err());
//~^ ERROR attempt to divide by zero
assert!(thread::spawn(move|| { isize::MIN % -1; }).join().is_err());
//~^ ERROR attempt to calculate the remainder with overflow
//~| ERROR this expression will panic at runtime
Expand All @@ -47,6 +52,9 @@ fn main() {
assert!(thread::spawn(move|| { i64::MIN % -1; }).join().is_err());
//~^ ERROR attempt to calculate the remainder with overflow
//~| ERROR this expression will panic at runtime
assert!(thread::spawn(move|| { i128::MIN % -1; }).join().is_err());
//~^ ERROR attempt to calculate the remainder with overflow
//~| ERROR this expression will panic at runtime
assert!(thread::spawn(move|| { 1isize % 0; }).join().is_err());
//~^ ERROR attempt to calculate the remainder with a divisor of zero
assert!(thread::spawn(move|| { 1i8 % 0; }).join().is_err());
Expand All @@ -57,4 +65,6 @@ fn main() {
//~^ ERROR attempt to calculate the remainder with a divisor of zero
assert!(thread::spawn(move|| { 1i64 % 0; }).join().is_err());
//~^ ERROR attempt to calculate the remainder with a divisor of zero
assert!(thread::spawn(move|| { 1i128 % 0; }).join().is_err());
//~^ ERROR attempt to calculate the remainder with a divisor of zero
}
78 changes: 57 additions & 21 deletions src/test/ui/issues/issue-8460-const.stderr
Expand Up @@ -64,125 +64,161 @@ error: this expression will panic at runtime
LL | assert!(thread::spawn(move|| { i64::MIN / -1; }).join().is_err());
| ^^^^^^^^^^^^^ attempt to divide with overflow

error: attempt to divide by zero
error: attempt to divide with overflow
--> $DIR/issue-8460-const.rs:25:36
|
LL | assert!(thread::spawn(move|| { i128::MIN / -1; }).join().is_err());
| ^^^^^^^^^^^^^^

error: this expression will panic at runtime
--> $DIR/issue-8460-const.rs:25:36
|
LL | assert!(thread::spawn(move|| { i128::MIN / -1; }).join().is_err());
| ^^^^^^^^^^^^^^ attempt to divide with overflow

error: attempt to divide by zero
--> $DIR/issue-8460-const.rs:28:36
|
LL | assert!(thread::spawn(move|| { 1isize / 0; }).join().is_err());
| ^^^^^^^^^^

error: attempt to divide by zero
--> $DIR/issue-8460-const.rs:27:36
--> $DIR/issue-8460-const.rs:30:36
|
LL | assert!(thread::spawn(move|| { 1i8 / 0; }).join().is_err());
| ^^^^^^^

error: attempt to divide by zero
--> $DIR/issue-8460-const.rs:29:36
--> $DIR/issue-8460-const.rs:32:36
|
LL | assert!(thread::spawn(move|| { 1i16 / 0; }).join().is_err());
| ^^^^^^^^

error: attempt to divide by zero
--> $DIR/issue-8460-const.rs:31:36
--> $DIR/issue-8460-const.rs:34:36
|
LL | assert!(thread::spawn(move|| { 1i32 / 0; }).join().is_err());
| ^^^^^^^^

error: attempt to divide by zero
--> $DIR/issue-8460-const.rs:33:36
--> $DIR/issue-8460-const.rs:36:36
|
LL | assert!(thread::spawn(move|| { 1i64 / 0; }).join().is_err());
| ^^^^^^^^

error: attempt to divide by zero
--> $DIR/issue-8460-const.rs:38:36
|
LL | assert!(thread::spawn(move|| { 1i128 / 0; }).join().is_err());
| ^^^^^^^^^

error: attempt to calculate the remainder with overflow
--> $DIR/issue-8460-const.rs:35:36
--> $DIR/issue-8460-const.rs:40:36
|
LL | assert!(thread::spawn(move|| { isize::MIN % -1; }).join().is_err());
| ^^^^^^^^^^^^^^^

error: this expression will panic at runtime
--> $DIR/issue-8460-const.rs:35:36
--> $DIR/issue-8460-const.rs:40:36
|
LL | assert!(thread::spawn(move|| { isize::MIN % -1; }).join().is_err());
| ^^^^^^^^^^^^^^^ attempt to calculate the remainder with overflow

error: attempt to calculate the remainder with overflow
--> $DIR/issue-8460-const.rs:38:36
--> $DIR/issue-8460-const.rs:43:36
|
LL | assert!(thread::spawn(move|| { i8::MIN % -1; }).join().is_err());
| ^^^^^^^^^^^^

error: this expression will panic at runtime
--> $DIR/issue-8460-const.rs:38:36
--> $DIR/issue-8460-const.rs:43:36
|
LL | assert!(thread::spawn(move|| { i8::MIN % -1; }).join().is_err());
| ^^^^^^^^^^^^ attempt to calculate the remainder with overflow

error: attempt to calculate the remainder with overflow
--> $DIR/issue-8460-const.rs:41:36
--> $DIR/issue-8460-const.rs:46:36
|
LL | assert!(thread::spawn(move|| { i16::MIN % -1; }).join().is_err());
| ^^^^^^^^^^^^^

error: this expression will panic at runtime
--> $DIR/issue-8460-const.rs:41:36
--> $DIR/issue-8460-const.rs:46:36
|
LL | assert!(thread::spawn(move|| { i16::MIN % -1; }).join().is_err());
| ^^^^^^^^^^^^^ attempt to calculate the remainder with overflow

error: attempt to calculate the remainder with overflow
--> $DIR/issue-8460-const.rs:44:36
--> $DIR/issue-8460-const.rs:49:36
|
LL | assert!(thread::spawn(move|| { i32::MIN % -1; }).join().is_err());
| ^^^^^^^^^^^^^

error: this expression will panic at runtime
--> $DIR/issue-8460-const.rs:44:36
--> $DIR/issue-8460-const.rs:49:36
|
LL | assert!(thread::spawn(move|| { i32::MIN % -1; }).join().is_err());
| ^^^^^^^^^^^^^ attempt to calculate the remainder with overflow

error: attempt to calculate the remainder with overflow
--> $DIR/issue-8460-const.rs:47:36
--> $DIR/issue-8460-const.rs:52:36
|
LL | assert!(thread::spawn(move|| { i64::MIN % -1; }).join().is_err());
| ^^^^^^^^^^^^^

error: this expression will panic at runtime
--> $DIR/issue-8460-const.rs:47:36
--> $DIR/issue-8460-const.rs:52:36
|
LL | assert!(thread::spawn(move|| { i64::MIN % -1; }).join().is_err());
| ^^^^^^^^^^^^^ attempt to calculate the remainder with overflow

error: attempt to calculate the remainder with overflow
--> $DIR/issue-8460-const.rs:55:36
|
LL | assert!(thread::spawn(move|| { i128::MIN % -1; }).join().is_err());
| ^^^^^^^^^^^^^^

error: this expression will panic at runtime
--> $DIR/issue-8460-const.rs:55:36
|
LL | assert!(thread::spawn(move|| { i128::MIN % -1; }).join().is_err());
| ^^^^^^^^^^^^^^ attempt to calculate the remainder with overflow

error: attempt to calculate the remainder with a divisor of zero
--> $DIR/issue-8460-const.rs:50:36
--> $DIR/issue-8460-const.rs:58:36
|
LL | assert!(thread::spawn(move|| { 1isize % 0; }).join().is_err());
| ^^^^^^^^^^

error: attempt to calculate the remainder with a divisor of zero
--> $DIR/issue-8460-const.rs:52:36
--> $DIR/issue-8460-const.rs:60:36
|
LL | assert!(thread::spawn(move|| { 1i8 % 0; }).join().is_err());
| ^^^^^^^

error: attempt to calculate the remainder with a divisor of zero
--> $DIR/issue-8460-const.rs:54:36
--> $DIR/issue-8460-const.rs:62:36
|
LL | assert!(thread::spawn(move|| { 1i16 % 0; }).join().is_err());
| ^^^^^^^^

error: attempt to calculate the remainder with a divisor of zero
--> $DIR/issue-8460-const.rs:56:36
--> $DIR/issue-8460-const.rs:64:36
|
LL | assert!(thread::spawn(move|| { 1i32 % 0; }).join().is_err());
| ^^^^^^^^

error: attempt to calculate the remainder with a divisor of zero
--> $DIR/issue-8460-const.rs:58:36
--> $DIR/issue-8460-const.rs:66:36
|
LL | assert!(thread::spawn(move|| { 1i64 % 0; }).join().is_err());
| ^^^^^^^^

error: aborting due to 30 previous errors
error: attempt to calculate the remainder with a divisor of zero
--> $DIR/issue-8460-const.rs:68:36
|
LL | assert!(thread::spawn(move|| { 1i128 % 0; }).join().is_err());
| ^^^^^^^^^

error: aborting due to 36 previous errors

10 changes: 9 additions & 1 deletion src/test/ui/issues/issue-8460-const2.rs
Expand Up @@ -3,7 +3,7 @@

#![deny(const_err)]

use std::{isize, i8, i16, i32, i64};
use std::{isize, i8, i16, i32, i64, i128};
use std::thread;

fn main() {
Expand All @@ -17,6 +17,8 @@ fn main() {
//~^ ERROR attempt to divide with overflow
assert!(thread::spawn(move|| { i64::MIN / -1; }).join().is_err());
//~^ ERROR attempt to divide with overflow
assert!(thread::spawn(move|| { i128::MIN / -1; }).join().is_err());
//~^ ERROR attempt to divide with overflow
assert!(thread::spawn(move|| { 1isize / 0; }).join().is_err());
//~^ ERROR attempt to divide by zero
assert!(thread::spawn(move|| { 1i8 / 0; }).join().is_err());
Expand All @@ -27,6 +29,8 @@ fn main() {
//~^ ERROR attempt to divide by zero
assert!(thread::spawn(move|| { 1i64 / 0; }).join().is_err());
//~^ ERROR attempt to divide by zero
assert!(thread::spawn(move|| { 1i128 / 0; }).join().is_err());
//~^ ERROR attempt to divide by zero
assert!(thread::spawn(move|| { isize::MIN % -1; }).join().is_err());
//~^ ERROR attempt to calculate the remainder with overflow
assert!(thread::spawn(move|| { i8::MIN % -1; }).join().is_err());
Expand All @@ -37,6 +41,8 @@ fn main() {
//~^ ERROR attempt to calculate the remainder with overflow
assert!(thread::spawn(move|| { i64::MIN % -1; }).join().is_err());
//~^ ERROR attempt to calculate the remainder with overflow
assert!(thread::spawn(move|| { i128::MIN % -1; }).join().is_err());
//~^ ERROR attempt to calculate the remainder with overflow
assert!(thread::spawn(move|| { 1isize % 0; }).join().is_err());
//~^ ERROR attempt to calculate the remainder with a divisor of zero
assert!(thread::spawn(move|| { 1i8 % 0; }).join().is_err());
Expand All @@ -47,4 +53,6 @@ fn main() {
//~^ ERROR attempt to calculate the remainder with a divisor of zero
assert!(thread::spawn(move|| { 1i64 % 0; }).join().is_err());
//~^ ERROR attempt to calculate the remainder with a divisor of zero
assert!(thread::spawn(move|| { 1i128 % 0; }).join().is_err());
//~^ ERROR attempt to calculate the remainder with a divisor of zero
}

0 comments on commit 1ddb050

Please sign in to comment.