Skip to content

Commit 8ee77a2

Browse files
committed
Use try_fold instead of manually carrying an accumulator
1 parent a6946a8 commit 8ee77a2

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/librustc_mir/interpret/operand.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
477477
) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> {
478478
use rustc::mir::PlaceBase;
479479

480-
let mut op = match &place.base {
480+
let base_op = match &place.base {
481481
PlaceBase::Local(mir::RETURN_PLACE) =>
482482
throw_unsup!(ReadFromReturnPointer),
483483
PlaceBase::Local(local) => {
@@ -497,9 +497,10 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
497497
}
498498
};
499499

500-
for elem in place.projection.iter() {
501-
op = self.operand_projection(op, elem)?
502-
}
500+
let op = place.projection.iter().try_fold(
501+
base_op,
502+
|op, elem| self.operand_projection(op, elem)
503+
)?;
503504

504505
trace!("eval_place_to_op: got {:?}", *op);
505506
Ok(op)

0 commit comments

Comments
 (0)