Skip to content

Commit

Permalink
Fix condition and tests' flags
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnTitor committed Sep 1, 2019
1 parent 8e9825a commit 0cd9c16
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 141 deletions.
1 change: 1 addition & 0 deletions src/librustc_mir/transform/const_prop.rs
Expand Up @@ -413,6 +413,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
// We check overflow in debug mode already
// so should only check in release mode.
if !oflo_check
&& prim.layout.ty.is_signed()
&& prim.to_bits()? == (1 << (prim.layout.size.bits() - 1)) {
throw_panic!(OverflowNeg)
}
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/consts/const-err2.rs
Expand Up @@ -5,6 +5,8 @@

#![feature(rustc_attrs)]
#![allow(exceeding_bitshifts)]
// compile-flags: -C overflow-checks=on -O

#![deny(const_err)]

fn black_box<T>(_: T) {
Expand Down
28 changes: 14 additions & 14 deletions src/test/ui/consts/const-err2.stderr
@@ -1,35 +1,35 @@
error: this expression will panic at runtime
--> $DIR/const-err2.rs:15:13
error: attempt to negate with overflow
--> $DIR/const-err2.rs:17:13
|
LL | let a = -std::i8::MIN;
| ^^^^^^^^^^^^^ attempt to negate with overflow
| ^^^^^^^^^^^^^
|
note: lint level defined here
--> $DIR/const-err2.rs:8:9
--> $DIR/const-err2.rs:10:9
|
LL | #![deny(const_err)]
| ^^^^^^^^^

error: this expression will panic at runtime
--> $DIR/const-err2.rs:17:13
error: attempt to add with overflow
--> $DIR/const-err2.rs:19:13
|
LL | let b = 200u8 + 200u8 + 200u8;
| ^^^^^^^^^^^^^ attempt to add with overflow
| ^^^^^^^^^^^^^

error: this expression will panic at runtime
--> $DIR/const-err2.rs:19:13
error: attempt to multiply with overflow
--> $DIR/const-err2.rs:21:13
|
LL | let c = 200u8 * 4;
| ^^^^^^^^^ attempt to multiply with overflow
| ^^^^^^^^^

error: this expression will panic at runtime
--> $DIR/const-err2.rs:21:13
error: attempt to subtract with overflow
--> $DIR/const-err2.rs:23:13
|
LL | let d = 42u8 - (42u8 + 1);
| ^^^^^^^^^^^^^^^^^ attempt to subtract with overflow
| ^^^^^^^^^^^^^^^^^

error: index out of bounds: the len is 1 but the index is 1
--> $DIR/const-err2.rs:23:14
--> $DIR/const-err2.rs:25:14
|
LL | let _e = [5u8][1];
| ^^^^^^^^
Expand Down
5 changes: 3 additions & 2 deletions src/test/ui/consts/const-eval/promoted_errors.rs
@@ -1,11 +1,12 @@
// compile-flags: -O
// compile-flags: -C overflow-checks=on -O

#![deny(const_err)]

fn main() {
println!("{}", 0u32 - 1);
//~^ ERROR attempt to subtract with overflow
let _x = 0u32 - 1;
//~^ ERROR this expression will panic at runtime [const_err]
//~^ ERROR attempt to subtract with overflow
println!("{}", 1/(1-1));
//~^ ERROR attempt to divide by zero [const_err]
//~| ERROR reaching this expression at runtime will panic or abort [const_err]
Expand Down
32 changes: 19 additions & 13 deletions src/test/ui/consts/const-eval/promoted_errors.stderr
@@ -1,62 +1,68 @@
error: this expression will panic at runtime
--> $DIR/promoted_errors.rs:7:14
error: attempt to subtract with overflow
--> $DIR/promoted_errors.rs:6:20
|
LL | let _x = 0u32 - 1;
| ^^^^^^^^ attempt to subtract with overflow
LL | println!("{}", 0u32 - 1);
| ^^^^^^^^
|
note: lint level defined here
--> $DIR/promoted_errors.rs:3:9
|
LL | #![deny(const_err)]
| ^^^^^^^^^

error: attempt to subtract with overflow
--> $DIR/promoted_errors.rs:8:14
|
LL | let _x = 0u32 - 1;
| ^^^^^^^^

error: attempt to divide by zero
--> $DIR/promoted_errors.rs:9:20
--> $DIR/promoted_errors.rs:10:20
|
LL | println!("{}", 1/(1-1));
| ^^^^^^^

error: reaching this expression at runtime will panic or abort
--> $DIR/promoted_errors.rs:9:20
--> $DIR/promoted_errors.rs:10:20
|
LL | println!("{}", 1/(1-1));
| ^^^^^^^ attempt to divide by zero

error: attempt to divide by zero
--> $DIR/promoted_errors.rs:12:14
--> $DIR/promoted_errors.rs:13:14
|
LL | let _x = 1/(1-1);
| ^^^^^^^

error: this expression will panic at runtime
--> $DIR/promoted_errors.rs:12:14
--> $DIR/promoted_errors.rs:13:14
|
LL | let _x = 1/(1-1);
| ^^^^^^^ attempt to divide by zero

error: attempt to divide by zero
--> $DIR/promoted_errors.rs:15:20
--> $DIR/promoted_errors.rs:16:20
|
LL | println!("{}", 1/(false as u32));
| ^^^^^^^^^^^^^^^^

error: reaching this expression at runtime will panic or abort
--> $DIR/promoted_errors.rs:15:20
--> $DIR/promoted_errors.rs:16:20
|
LL | println!("{}", 1/(false as u32));
| ^^^^^^^^^^^^^^^^ attempt to divide by zero

error: attempt to divide by zero
--> $DIR/promoted_errors.rs:18:14
--> $DIR/promoted_errors.rs:19:14
|
LL | let _x = 1/(false as u32);
| ^^^^^^^^^^^^^^^^

error: this expression will panic at runtime
--> $DIR/promoted_errors.rs:18:14
--> $DIR/promoted_errors.rs:19:14
|
LL | let _x = 1/(false as u32);
| ^^^^^^^^^^^^^^^^ attempt to divide by zero

error: aborting due to 9 previous errors
error: aborting due to 10 previous errors

4 changes: 3 additions & 1 deletion src/test/ui/consts/issue-64059.rs
@@ -1,4 +1,6 @@
// compile-flags: -C overflow-checks=on -O
// run-pass

fn main() {
let _ = -(-0.0);
//~^ ERROR: this expression will panic at runtime
}
10 changes: 0 additions & 10 deletions src/test/ui/consts/issue-64059.stderr

This file was deleted.

12 changes: 2 additions & 10 deletions src/test/ui/issues/issue-8460-const.rs
@@ -1,3 +1,5 @@
// compile-flags: -C overflow-checks=on -O

#![deny(const_err)]

use std::{isize, i8, i16, i32, i64};
Expand All @@ -6,19 +8,14 @@ use std::thread;
fn main() {
assert!(thread::spawn(move|| { isize::MIN / -1; }).join().is_err());
//~^ ERROR attempt to divide with overflow
//~| ERROR this expression will panic at runtime
assert!(thread::spawn(move|| { i8::MIN / -1; }).join().is_err());
//~^ ERROR attempt to divide with overflow
//~| ERROR this expression will panic at runtime
assert!(thread::spawn(move|| { i16::MIN / -1; }).join().is_err());
//~^ ERROR attempt to divide with overflow
//~| ERROR this expression will panic at runtime
assert!(thread::spawn(move|| { i32::MIN / -1; }).join().is_err());
//~^ ERROR attempt to divide with overflow
//~| ERROR this expression will panic at runtime
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|| { 1isize / 0; }).join().is_err());
//~^ ERROR attempt to divide by zero
//~| ERROR this expression will panic at runtime
Expand All @@ -36,19 +33,14 @@ fn main() {
//~| ERROR this expression will panic at runtime
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
assert!(thread::spawn(move|| { i8::MIN % -1; }).join().is_err());
//~^ ERROR attempt to calculate the remainder with overflow
//~| ERROR this expression will panic at runtime
assert!(thread::spawn(move|| { i16::MIN % -1; }).join().is_err());
//~^ ERROR attempt to calculate the remainder with overflow
//~| ERROR this expression will panic at runtime
assert!(thread::spawn(move|| { i32::MIN % -1; }).join().is_err());
//~^ ERROR attempt to calculate the remainder with overflow
//~| ERROR this expression will panic at runtime
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|| { 1isize % 0; }).join().is_err());
//~^ ERROR attempt to calculate the remainder with a divisor of zero
//~| ERROR this expression will panic at runtime
Expand Down

0 comments on commit 0cd9c16

Please sign in to comment.