Get LocalDefId from source instead of passing in

This commit is contained in:
Simon Vandel Sillesen 2020-09-19 13:52:55 +02:00
parent b4bdaa14f2
commit d3338dcf4d
2 changed files with 3 additions and 11 deletions

View File

@ -462,7 +462,7 @@ fn run_optimization_passes<'tcx>(
// The main optimizations that we do on MIR.
let optimizations: &[&dyn MirPass<'tcx>] = &[
&remove_unneeded_drops::RemoveUnneededDrops::new(def_id),
&remove_unneeded_drops::RemoveUnneededDrops,
&match_branches::MatchBranchSimplification,
// inst combine is after MatchBranchSimplification to clean up Ne(_1, false)
&instcombine::InstCombine,

View File

@ -6,15 +6,7 @@ use rustc_middle::mir::visit::Visitor;
use rustc_middle::mir::*;
use rustc_middle::ty::TyCtxt;
pub struct RemoveUnneededDrops {
def_id: LocalDefId,
}
impl RemoveUnneededDrops {
pub fn new(def_id: LocalDefId) -> Self {
Self { def_id }
}
}
pub struct RemoveUnneededDrops;
impl<'tcx> MirPass<'tcx> for RemoveUnneededDrops {
fn run_pass(&self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut Body<'tcx>) {
@ -23,7 +15,7 @@ impl<'tcx> MirPass<'tcx> for RemoveUnneededDrops {
tcx,
body,
optimizations: vec![],
def_id: self.def_id,
def_id: source.def_id().expect_local(),
};
opt_finder.visit_body(body);
for (loc, target) in opt_finder.optimizations {