Skip to content

Commit

Permalink
Use predefined helper instead of a new one
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed Aug 3, 2021
1 parent 30bc5a9 commit 0168dfe
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions compiler/rustc_mir/src/transform/abort_unwinding_calls.rs
Expand Up @@ -125,28 +125,17 @@ impl<'tcx> MirPass<'tcx> for AbortUnwindingCalls {
let abort_bb = body.basic_blocks_mut().push(bb);

for bb in calls_to_terminate {
let cleanup = get_cleanup(body.basic_blocks_mut()[bb].terminator_mut());
let cleanup = body.basic_blocks_mut()[bb].terminator_mut().unwind_mut().unwrap();
*cleanup = Some(abort_bb);
}
}

for id in cleanups_to_remove {
let cleanup = get_cleanup(body.basic_blocks_mut()[id].terminator_mut());
let cleanup = body.basic_blocks_mut()[id].terminator_mut().unwind_mut().unwrap();
*cleanup = None;
}

// We may have invalidated some `cleanup` blocks so clean those up now.
super::simplify::remove_dead_blocks(tcx, body);
}
}

fn get_cleanup<'a>(t: &'a mut Terminator<'_>) -> &'a mut Option<BasicBlock> {
match &mut t.kind {
TerminatorKind::Call { cleanup, .. }
| TerminatorKind::Drop { unwind: cleanup, .. }
| TerminatorKind::DropAndReplace { unwind: cleanup, .. }
| TerminatorKind::Assert { cleanup, .. }
| TerminatorKind::FalseUnwind { unwind: cleanup, .. } => cleanup,
_ => unreachable!(),
}
}

0 comments on commit 0168dfe

Please sign in to comment.