Skip to content

Commit

Permalink
Fix const_err with -(-0.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnTitor committed Sep 1, 2019
1 parent d0677b9 commit 35c9e5f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 27 deletions.
14 changes: 1 addition & 13 deletions src/librustc_mir/transform/const_prop.rs
Expand Up @@ -6,7 +6,7 @@ use std::cell::Cell;
use rustc::hir::def::DefKind;
use rustc::mir::{
AggregateKind, Constant, Location, Place, PlaceBase, Body, Operand, Rvalue,
Local, NullOp, UnOp, StatementKind, Statement, LocalKind, Static, StaticKind,
Local, NullOp, StatementKind, Statement, LocalKind, Static, StaticKind,
TerminatorKind, Terminator, ClearCrossCrate, SourceInfo, BinOp, ProjectionElem,
SourceScope, SourceScopeLocalData, LocalDecl,
};
Expand Down Expand Up @@ -407,18 +407,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
let arg = self.eval_operand(arg, source_info)?;
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)) {
throw_panic!(OverflowNeg)
}
}
UnOp::Not => {
// Cannot overflow
}
}
// Now run the actual operation.
this.ecx.unary_op(op, prim)
})?;
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/consts/const-err2.rs
Expand Up @@ -13,7 +13,6 @@ 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;
Expand Down
20 changes: 7 additions & 13 deletions src/test/ui/consts/const-err2.stderr
@@ -1,8 +1,8 @@
error: this expression will panic at runtime
--> $DIR/const-err2.rs:15:13
--> $DIR/const-err2.rs:16:13
|
LL | let a = -std::i8::MIN;
| ^^^^^^^^^^^^^ attempt to negate with overflow
LL | let b = 200u8 + 200u8 + 200u8;
| ^^^^^^^^^^^^^ attempt to add with overflow
|
note: lint level defined here
--> $DIR/const-err2.rs:8:9
Expand All @@ -11,28 +11,22 @@ 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
--> $DIR/const-err2.rs:18:13
|
LL | let c = 200u8 * 4;
| ^^^^^^^^^ attempt to multiply with overflow

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

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

5 changes: 5 additions & 0 deletions src/test/ui/consts/issue-64059.rs
@@ -0,0 +1,5 @@
// run-pass

fn main() {
let _ = -(-0.0);
}

0 comments on commit 35c9e5f

Please sign in to comment.