Separate RemoveFalseEdges
from SimplifyBranches
Otherwise dataflow state will propagate along false edges and cause things to be marked as maybe init unnecessarily. These should be separate, since `SimplifyBranches` also makes `if true {} else {}` into a `goto`, which means we wouldn't lint anything in the `else` block.
This commit is contained in:
parent
6db0a0e9a4
commit
bb27b05104
3 changed files with 38 additions and 15 deletions
|
@ -1,22 +1,21 @@
|
|||
//! A pass that simplifies branches when their condition is known.
|
||||
|
||||
use crate::MirPass;
|
||||
use rustc_middle::mir::*;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
||||
pub struct SimplifyBranches {
|
||||
/// A pass that replaces a branch with a goto when its condition is known.
|
||||
pub struct SimplifyConstCondition {
|
||||
label: String,
|
||||
}
|
||||
|
||||
impl SimplifyBranches {
|
||||
impl SimplifyConstCondition {
|
||||
pub fn new(label: &str) -> Self {
|
||||
SimplifyBranches { label: format!("SimplifyBranches-{}", label) }
|
||||
SimplifyConstCondition { label: format!("SimplifyConstCondition-{}", label) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> MirPass<'tcx> for SimplifyBranches {
|
||||
impl<'tcx> MirPass<'tcx> for SimplifyConstCondition {
|
||||
fn name(&self) -> Cow<'_, str> {
|
||||
Cow::Borrowed(&self.label)
|
||||
}
|
||||
|
@ -53,12 +52,6 @@ impl<'tcx> MirPass<'tcx> for SimplifyBranches {
|
|||
Some(v) if v == expected => TerminatorKind::Goto { target },
|
||||
_ => continue,
|
||||
},
|
||||
TerminatorKind::FalseEdge { real_target, .. } => {
|
||||
TerminatorKind::Goto { target: real_target }
|
||||
}
|
||||
TerminatorKind::FalseUnwind { real_target, .. } => {
|
||||
TerminatorKind::Goto { target: real_target }
|
||||
}
|
||||
_ => continue,
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue