Skip to content

Commit

Permalink
Use try_fold instead of manually carrying an accumulator
Browse files Browse the repository at this point in the history
  • Loading branch information
spastorino committed Sep 14, 2019
1 parent a6946a8 commit 8ee77a2
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/librustc_mir/interpret/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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)
Expand Down

0 comments on commit 8ee77a2

Please sign in to comment.