1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! This pass removes the unwind branch of all the terminators when the no-landing-pads option is
14 use rustc
::ty
::TyCtxt
;
15 use rustc
::mir
::repr
::*;
16 use rustc
::mir
::visit
::MutVisitor
;
17 use rustc
::mir
::transform
::{Pass, MirPass, MirSource}
;
19 pub struct NoLandingPads
;
21 impl<'tcx
> MutVisitor
<'tcx
> for NoLandingPads
{
22 fn visit_terminator(&mut self, bb
: BasicBlock
, terminator
: &mut Terminator
<'tcx
>) {
23 match terminator
.kind
{
24 TerminatorKind
::Goto { .. }
|
25 TerminatorKind
::Resume
|
26 TerminatorKind
::Return
|
27 TerminatorKind
::If { .. }
|
28 TerminatorKind
::Switch { .. }
|
29 TerminatorKind
::SwitchInt { .. }
=> {
32 TerminatorKind
::Drop { ref mut unwind, .. }
=> {
35 TerminatorKind
::Call { ref mut cleanup, .. }
=> {
39 self.super_terminator(bb
, terminator
);
43 impl<'tcx
> MirPass
<'tcx
> for NoLandingPads
{
44 fn run_pass
<'a
>(&mut self, tcx
: TyCtxt
<'a
, 'tcx
, 'tcx
>,
45 _
: MirSource
, mir
: &mut Mir
<'tcx
>) {
46 if tcx
.sess
.no_landing_pads() {
52 impl Pass
for NoLandingPads {}