From 8ee77a268f1f90b6e99e31cd3c4d03f893b73a76 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sat, 14 Sep 2019 19:51:40 -0300 Subject: [PATCH] Use try_fold instead of manually carrying an accumulator --- src/librustc_mir/interpret/operand.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/librustc_mir/interpret/operand.rs b/src/librustc_mir/interpret/operand.rs index 06b7206f4292c..9ad1542905b68 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)