about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-09-15 02:29:47 +0200
committerGitHub <noreply@github.com>2019-09-15 02:29:47 +0200
commit82927cf826b01f4c53667c1a740eb2b3c091d271 (patch)
tree571171ca521d418d68445dc2a5e03b21f0d5b212
parent3e4c7786e9a25239308290ea6b82bc6ffba66bcc (diff)
parent8ee77a268f1f90b6e99e31cd3c4d03f893b73a76 (diff)
downloadrust-82927cf826b01f4c53667c1a740eb2b3c091d271.tar.gz
rust-82927cf826b01f4c53667c1a740eb2b3c091d271.zip
Rollup merge of #64473 - spastorino:use-try-fold, r=Centril
Use try_fold instead of manually carrying an accumulator

r? @RalfJung
-rw-r--r--src/librustc_mir/interpret/operand.rs9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/librustc_mir/interpret/operand.rs b/src/librustc_mir/interpret/operand.rs
index 06b7206f429..9ad1542905b 100644
--- a/src/librustc_mir/interpret/operand.rs
+++ b/src/librustc_mir/interpret/operand.rs
@@ -477,7 +477,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
     ) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> {
         use rustc::mir::PlaceBase;
 
-        let mut op = match &place.base {
+        let base_op = match &place.base {
             PlaceBase::Local(mir::RETURN_PLACE) =>
                 throw_unsup!(ReadFromReturnPointer),
             PlaceBase::Local(local) => {
@@ -497,9 +497,10 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
             }
         };
 
-        for elem in place.projection.iter() {
-            op = self.operand_projection(op, elem)?
-        }
+        let op = place.projection.iter().try_fold(
+            base_op,
+            |op, elem| self.operand_projection(op, elem)
+        )?;
 
         trace!("eval_place_to_op: got {:?}", *op);
         Ok(op)