1
Fork 0

Use predefined helper instead of a new one

This commit is contained in:
Alex Crichton 2021-08-02 07:27:17 -07:00
parent 30bc5a936b
commit 0168dfec6d

View file

@ -125,13 +125,13 @@ impl<'tcx> MirPass<'tcx> for AbortUnwindingCalls {
let abort_bb = body.basic_blocks_mut().push(bb); let abort_bb = body.basic_blocks_mut().push(bb);
for bb in calls_to_terminate { 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); *cleanup = Some(abort_bb);
} }
} }
for id in cleanups_to_remove { 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; *cleanup = None;
} }
@ -139,14 +139,3 @@ impl<'tcx> MirPass<'tcx> for AbortUnwindingCalls {
super::simplify::remove_dead_blocks(tcx, body); 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!(),
}
}