1 //! This pass removes the unwind branch of all the terminators when the no-landing-pads option is
4 use crate::transform::MirPass;
5 use rustc_middle::mir::visit::MutVisitor;
6 use rustc_middle::mir::*;
7 use rustc_middle::ty::TyCtxt;
8 use rustc_target::spec::PanicStrategy;
10 pub struct NoLandingPads<'tcx> {
14 impl<'tcx> NoLandingPads<'tcx> {
15 pub fn new(tcx: TyCtxt<'tcx>) -> Self {
20 impl<'tcx> MirPass<'tcx> for NoLandingPads<'tcx> {
21 fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
22 no_landing_pads(tcx, body)
26 pub fn no_landing_pads<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
27 if tcx.sess.panic_strategy() == PanicStrategy::Abort {
28 NoLandingPads::new(tcx).visit_body(body);
32 impl<'tcx> MutVisitor<'tcx> for NoLandingPads<'tcx> {
33 fn tcx(&self) -> TyCtxt<'tcx> {
37 fn visit_terminator(&mut self, terminator: &mut Terminator<'tcx>, location: Location) {
38 if let Some(unwind) = terminator.kind.unwind_mut() {
41 self.super_terminator(terminator, location);