Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/librustc_mir/transform/const_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,13 +405,13 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
}

let arg = self.eval_operand(arg, source_info)?;
let is_release_mode = self.tcx.sess.opts.debugging_opts.mir_opt_level >= 2;
let val = self.use_ecx(source_info, |this| {
let prim = this.ecx.read_immediate(arg)?;
match op {
UnOp::Neg => {
// Need to do overflow check here: For actual CTFE, MIR
// generation emits code that does this before calling the op.
if prim.to_bits()? == (1 << (prim.layout.size.bits() - 1)) {
if is_release_mode
&& prim.to_bits()? == (1 << (prim.layout.size.bits() - 1)) {
throw_panic!(OverflowNeg)
}
}
Expand Down Expand Up @@ -485,7 +485,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
Scalar::from_bool(overflow).into(),
)
} else {
if overflow {
if self.tcx.sess.opts.debugging_opts.mir_opt_level >= 2 && overflow {
let err = err_panic!(Overflow(op)).into();
let _: Option<()> = self.use_ecx(source_info, |_| Err(err));
return None;
Expand Down
4 changes: 0 additions & 4 deletions src/test/ui/consts/const-err2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,9 @@ fn black_box<T>(_: T) {

fn main() {
let a = -std::i8::MIN;
//~^ ERROR const_err
let b = 200u8 + 200u8 + 200u8;
//~^ ERROR const_err
let c = 200u8 * 4;
//~^ ERROR const_err
let d = 42u8 - (42u8 + 1);
//~^ ERROR const_err
let _e = [5u8][1];
//~^ ERROR const_err
black_box(a);
Expand Down
34 changes: 5 additions & 29 deletions src/test/ui/consts/const-err2.stderr
Original file line number Diff line number Diff line change
@@ -1,38 +1,14 @@
error: this expression will panic at runtime
--> $DIR/const-err2.rs:15:13
error: index out of bounds: the len is 1 but the index is 1
--> $DIR/const-err2.rs:19:14
|
LL | let a = -std::i8::MIN;
| ^^^^^^^^^^^^^ attempt to negate with overflow
LL | let _e = [5u8][1];
| ^^^^^^^^
|
note: lint level defined here
--> $DIR/const-err2.rs:8:9
|
LL | #![deny(const_err)]
| ^^^^^^^^^

error: this expression will panic at runtime
--> $DIR/const-err2.rs:17: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
|
LL | let c = 200u8 * 4;
| ^^^^^^^^^ attempt to multiply with overflow

error: this expression will panic at runtime
--> $DIR/const-err2.rs:21: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
|
LL | let _e = [5u8][1];
| ^^^^^^^^

error: aborting due to 5 previous errors
error: aborting due to previous error

1 change: 0 additions & 1 deletion src/test/ui/consts/const-eval/promoted_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
fn main() {
println!("{}", 0u32 - 1);
let _x = 0u32 - 1;
//~^ ERROR this expression will panic at runtime [const_err]
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
30 changes: 12 additions & 18 deletions src/test/ui/consts/const-eval/promoted_errors.stderr
Original file line number Diff line number Diff line change
@@ -1,62 +1,56 @@
error: this expression will panic at runtime
--> $DIR/promoted_errors.rs:7:14
error: attempt to divide by zero
--> $DIR/promoted_errors.rs:8:20
|
LL | let _x = 0u32 - 1;
| ^^^^^^^^ attempt to subtract with overflow
LL | println!("{}", 1/(1-1));
| ^^^^^^^
|
note: lint level defined here
--> $DIR/promoted_errors.rs:3:9
|
LL | #![deny(const_err)]
| ^^^^^^^^^

error: attempt to divide by zero
--> $DIR/promoted_errors.rs:9: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:8: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:11:14
|
LL | let _x = 1/(1-1);
| ^^^^^^^

error: this expression will panic at runtime
--> $DIR/promoted_errors.rs:12:14
--> $DIR/promoted_errors.rs:11: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:14: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:14: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:17: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:17:14
|
LL | let _x = 1/(false as u32);
| ^^^^^^^^^^^^^^^^ attempt to divide by zero

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

5 changes: 5 additions & 0 deletions src/test/ui/consts/issue-64059.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// run-pass

fn main() {
let _ = -(-0.0);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
error: failed to remove $TEST_BUILD_DIR/issues/issue-8171-default-method-self-inherit-builtin-trait/issue-8171-default-method-self-inherit-builtin-trait.issue_8171_default_method_self_inherit_builtin_trait.7rcbfp3g-cgu.0.rcgu.o: 指定されたパスが見つかりません。 (os error 3)

error: failed to remove $TEST_BUILD_DIR/issues/issue-8171-default-method-self-inherit-builtin-trait/issue-8171-default-method-self-inherit-builtin-trait.issue_8171_default_method_self_inherit_builtin_trait.7rcbfp3g-cgu.1.rcgu.o: 指定されたパスが見つかりません。 (os error 3)

error: aborting due to 2 previous errors

10 changes: 0 additions & 10 deletions src/test/ui/issues/issue-8460-const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,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 +31,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
Loading