diff options
| author | bors <bors@rust-lang.org> | 2017-12-05 13:35:59 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-12-05 13:35:59 +0000 |
| commit | bf2be6175e9f6414dd5ce19d120dcd444d79edea (patch) | |
| tree | 07d6be2043c73c463362476171134d78619e679f /src | |
| parent | a2899408dd162bfe349e7ff8bceaee60b34e77cc (diff) | |
| parent | 2a629f931df9daefecdcc9befe3698f556b3572d (diff) | |
| download | rust-bf2be6175e9f6414dd5ce19d120dcd444d79edea.tar.gz rust-bf2be6175e9f6414dd5ce19d120dcd444d79edea.zip | |
Auto merge of #46492 - eddyb:move-ops, r=arielb1
rustc_mir: don't move temporaries that are still used later. This should unbreak using the MIR borrow-checker on `libcore` (assuming #46268 is merged).
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/mir/mod.rs | 6 | ||||
| -rw-r--r-- | src/librustc_mir/build/expr/as_rvalue.rs | 8 | ||||
| -rw-r--r-- | src/test/run-pass/i128.rs | 2 | ||||
| -rw-r--r-- | src/test/run-pass/u128.rs | 2 |
4 files changed, 14 insertions, 4 deletions
diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 5e5b9dc4d84..c803e76aebe 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -1347,6 +1347,12 @@ impl<'tcx> Operand<'tcx> { }) } + pub fn to_copy(&self) -> Self { + match *self { + Operand::Copy(_) | Operand::Constant(_) => self.clone(), + Operand::Move(ref place) => Operand::Copy(place.clone()) + } + } } /////////////////////////////////////////////////////////////////////////// diff --git a/src/librustc_mir/build/expr/as_rvalue.rs b/src/librustc_mir/build/expr/as_rvalue.rs index 88f1fb4f575..ee0b7bb7a8b 100644 --- a/src/librustc_mir/build/expr/as_rvalue.rs +++ b/src/librustc_mir/build/expr/as_rvalue.rs @@ -87,7 +87,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { let is_min = this.temp(bool_ty, expr_span); this.cfg.push_assign(block, source_info, &is_min, - Rvalue::BinaryOp(BinOp::Eq, arg.clone(), minval)); + Rvalue::BinaryOp(BinOp::Eq, arg.to_copy(), minval)); let err = ConstMathErr::Overflow(Op::Neg); block = this.assert(block, Operand::Move(is_min), false, @@ -346,7 +346,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { let is_zero = self.temp(bool_ty, span); let zero = self.zero_literal(span, ty); self.cfg.push_assign(block, source_info, &is_zero, - Rvalue::BinaryOp(BinOp::Eq, rhs.clone(), zero)); + Rvalue::BinaryOp(BinOp::Eq, rhs.to_copy(), zero)); block = self.assert(block, Operand::Move(is_zero), false, AssertMessage::Math(zero_err), span); @@ -364,9 +364,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { // this does (rhs == -1) & (lhs == MIN). It could short-circuit instead self.cfg.push_assign(block, source_info, &is_neg_1, - Rvalue::BinaryOp(BinOp::Eq, rhs.clone(), neg_1)); + Rvalue::BinaryOp(BinOp::Eq, rhs.to_copy(), neg_1)); self.cfg.push_assign(block, source_info, &is_min, - Rvalue::BinaryOp(BinOp::Eq, lhs.clone(), min)); + Rvalue::BinaryOp(BinOp::Eq, lhs.to_copy(), min)); let is_neg_1 = Operand::Move(is_neg_1); let is_min = Operand::Move(is_min); diff --git a/src/test/run-pass/i128.rs b/src/test/run-pass/i128.rs index 5369b138b0d..c3e43c92590 100644 --- a/src/test/run-pass/i128.rs +++ b/src/test/run-pass/i128.rs @@ -10,6 +10,8 @@ // ignore-emscripten i128 doesn't work +// compile-flags: -Z borrowck=compare + #![feature(i128_type, test)] extern crate test; diff --git a/src/test/run-pass/u128.rs b/src/test/run-pass/u128.rs index bf506a71250..ebd43a86033 100644 --- a/src/test/run-pass/u128.rs +++ b/src/test/run-pass/u128.rs @@ -10,6 +10,8 @@ // ignore-emscripten u128 not supported +// compile-flags: -Z borrowck=compare + #![feature(i128_type, test)] extern crate test; |
