]> git.lizzy.rs Git - rust.git/blob - src/librustc_mir/transform/no_landing_pads.rs
Rollup merge of #61518 - czipperz:const-fn-doc-disallow-loops, r=Centril
[rust.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<'a, 'tcx>(&self,
13                           tcx: TyCtxt<'a, 'tcx, 'tcx>,
14                           _: MirSource<'tcx>,
15                           body: &mut Body<'tcx>) {
16         no_landing_pads(tcx, body)
17     }
18 }
19
20 pub fn no_landing_pads<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, body: &mut Body<'tcx>) {
21     if tcx.sess.no_landing_pads() {
22         NoLandingPads.visit_body(body);
23     }
24 }
25
26 impl<'tcx> MutVisitor<'tcx> for NoLandingPads {
27     fn visit_terminator_kind(&mut self,
28                         kind: &mut TerminatorKind<'tcx>,
29                         location: Location) {
30         if let Some(unwind) = kind.unwind_mut() {
31             unwind.take();
32         }
33         self.super_terminator_kind(kind, location);
34     }
35 }