]> git.lizzy.rs Git - rust.git/commitdiff
rustc_mir: don't move temporaries that are still used later.
authorEduard-Mihai Burtescu <edy.burt@gmail.com>
Mon, 4 Dec 2017 15:46:23 +0000 (17:46 +0200)
committerEduard-Mihai Burtescu <edy.burt@gmail.com>
Tue, 5 Dec 2017 10:59:07 +0000 (12:59 +0200)
src/librustc/mir/mod.rs
src/librustc_mir/build/expr/as_rvalue.rs
src/test/run-pass/i128.rs
src/test/run-pass/u128.rs

index cd4ed8081c3bda662c6dd59567ab205e0a820fcf..1915a7de23f6ace607ac97729bede087e8b92979 100644 (file)
@@ -1347,6 +1347,12 @@ pub fn function_handle<'a>(
         })
     }
 
+    pub fn to_copy(&self) -> Self {
+        match *self {
+            Operand::Copy(_) | Operand::Constant(_) => self.clone(),
+            Operand::Move(ref place) => Operand::Copy(place.clone())
+        }
+    }
 }
 
 ///////////////////////////////////////////////////////////////////////////
index 88f1fb4f57518a3a3330b686b663bde1a6448408..ee0b7bb7a8bc48f6369a2520c7c464492fd288c6 100644 (file)
@@ -87,7 +87,7 @@ fn expr_as_rvalue(&mut self,
                     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 @@ pub fn build_binary_op(&mut self, mut block: BasicBlock,
                 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 @@ pub fn build_binary_op(&mut self, mut block: BasicBlock,
                     // 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);
index 5369b138b0d584a0a91f6e523245736e64129a8b..c3e43c92590ed0462c9b48f6b9716e52101a87e0 100644 (file)
@@ -10,6 +10,8 @@
 
 // ignore-emscripten i128 doesn't work
 
+// compile-flags: -Z borrowck=compare
+
 #![feature(i128_type, test)]
 
 extern crate test;
index bf506a712500178e0f6c6f749d9f2ef71f25a029..ebd43a860338602ba3bddc32165a3587748a9b19 100644 (file)
@@ -10,6 +10,8 @@
 
 // ignore-emscripten u128 not supported
 
+// compile-flags: -Z borrowck=compare
+
 #![feature(i128_type, test)]
 
 extern crate test;