Skip to content

Commit 2a629f9

Browse files
committed
rustc_mir: don't move temporaries that are still used later.
1 parent fdfbcf8 commit 2a629f9

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

src/librustc/mir/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1347,6 +1347,12 @@ impl<'tcx> Operand<'tcx> {
13471347
})
13481348
}
13491349

1350+
pub fn to_copy(&self) -> Self {
1351+
match *self {
1352+
Operand::Copy(_) | Operand::Constant(_) => self.clone(),
1353+
Operand::Move(ref place) => Operand::Copy(place.clone())
1354+
}
1355+
}
13501356
}
13511357

13521358
///////////////////////////////////////////////////////////////////////////

src/librustc_mir/build/expr/as_rvalue.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
8787
let is_min = this.temp(bool_ty, expr_span);
8888

8989
this.cfg.push_assign(block, source_info, &is_min,
90-
Rvalue::BinaryOp(BinOp::Eq, arg.clone(), minval));
90+
Rvalue::BinaryOp(BinOp::Eq, arg.to_copy(), minval));
9191

9292
let err = ConstMathErr::Overflow(Op::Neg);
9393
block = this.assert(block, Operand::Move(is_min), false,
@@ -346,7 +346,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
346346
let is_zero = self.temp(bool_ty, span);
347347
let zero = self.zero_literal(span, ty);
348348
self.cfg.push_assign(block, source_info, &is_zero,
349-
Rvalue::BinaryOp(BinOp::Eq, rhs.clone(), zero));
349+
Rvalue::BinaryOp(BinOp::Eq, rhs.to_copy(), zero));
350350

351351
block = self.assert(block, Operand::Move(is_zero), false,
352352
AssertMessage::Math(zero_err), span);
@@ -364,9 +364,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
364364
// this does (rhs == -1) & (lhs == MIN). It could short-circuit instead
365365

366366
self.cfg.push_assign(block, source_info, &is_neg_1,
367-
Rvalue::BinaryOp(BinOp::Eq, rhs.clone(), neg_1));
367+
Rvalue::BinaryOp(BinOp::Eq, rhs.to_copy(), neg_1));
368368
self.cfg.push_assign(block, source_info, &is_min,
369-
Rvalue::BinaryOp(BinOp::Eq, lhs.clone(), min));
369+
Rvalue::BinaryOp(BinOp::Eq, lhs.to_copy(), min));
370370

371371
let is_neg_1 = Operand::Move(is_neg_1);
372372
let is_min = Operand::Move(is_min);

src/test/run-pass/i128.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
// ignore-emscripten i128 doesn't work
1212

13+
// compile-flags: -Z borrowck=compare
14+
1315
#![feature(i128_type, test)]
1416

1517
extern crate test;

src/test/run-pass/u128.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
// ignore-emscripten u128 not supported
1212

13+
// compile-flags: -Z borrowck=compare
14+
1315
#![feature(i128_type, test)]
1416

1517
extern crate test;

0 commit comments

Comments
 (0)