]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_mir_transform/src/remove_false_edges.rs
Rollup merge of #105120 - solid-rs:patch/kmc-solid/maintainance, r=thomcc
[rust.git] / compiler / rustc_mir_transform / src / remove_false_edges.rs
1 use rustc_middle::mir::{Body, TerminatorKind};
2 use rustc_middle::ty::TyCtxt;
3
4 use crate::MirPass;
5
6 /// Removes `FalseEdge` and `FalseUnwind` terminators from the MIR.
7 ///
8 /// These are only needed for borrow checking, and can be removed afterwards.
9 ///
10 /// FIXME: This should probably have its own MIR phase.
11 pub struct RemoveFalseEdges;
12
13 impl<'tcx> MirPass<'tcx> for RemoveFalseEdges {
14     fn run_pass(&self, _: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
15         for block in body.basic_blocks_mut() {
16             let terminator = block.terminator_mut();
17             terminator.kind = match terminator.kind {
18                 TerminatorKind::FalseEdge { real_target, .. } => {
19                     TerminatorKind::Goto { target: real_target }
20                 }
21                 TerminatorKind::FalseUnwind { real_target, .. } => {
22                     TerminatorKind::Goto { target: real_target }
23                 }
24
25                 _ => continue,
26             }
27         }
28     }
29 }