]> git.proxmox.com Git - rustc.git/blob - src/librustc_mir/transform/no_landing_pads.rs
New upstream version 1.37.0+dfsg1
[rustc.git] / src / librustc_mir / transform / no_landing_pads.rs
1 //! This pass removes the unwind branch of all the terminators when the no-landing-pads option is
2 //! specified.
3
4 use rustc::ty::TyCtxt;
5 use rustc::mir::*;
6 use rustc::mir::visit::MutVisitor;
7 use crate::transform::{MirPass, MirSource};
8
9 pub struct NoLandingPads;
10
11 impl MirPass for NoLandingPads {
12 fn run_pass<'tcx>(&self, tcx: TyCtxt<'tcx>, _: MirSource<'tcx>, body: &mut Body<'tcx>) {
13 no_landing_pads(tcx, body)
14 }
15 }
16
17 pub fn no_landing_pads<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
18 if tcx.sess.no_landing_pads() {
19 NoLandingPads.visit_body(body);
20 }
21 }
22
23 impl<'tcx> MutVisitor<'tcx> for NoLandingPads {
24 fn visit_terminator_kind(&mut self,
25 kind: &mut TerminatorKind<'tcx>,
26 location: Location) {
27 if let Some(unwind) = kind.unwind_mut() {
28 unwind.take();
29 }
30 self.super_terminator_kind(kind, location);
31 }
32 }