Skip to content

Commit

Permalink
Don't run unused variable pass for stuff generated by #[derive()]
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth authored and zofrex committed Apr 17, 2018
1 parent 4ae9488 commit 24d410a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/librustc/middle/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ impl<'a, 'tcx> Visitor<'tcx> for IrMaps<'a, 'tcx> {
b: hir::BodyId, s: Span, id: NodeId) {
visit_fn(self, fk, fd, b, s, id);
}

fn visit_local(&mut self, l: &'tcx hir::Local) { visit_local(self, l); }
fn visit_expr(&mut self, ex: &'tcx Expr) { visit_expr(self, ex); }
fn visit_arm(&mut self, a: &'tcx hir::Arm) { visit_arm(self, a); }
Expand Down Expand Up @@ -361,6 +362,16 @@ fn visit_fn<'a, 'tcx: 'a>(ir: &mut IrMaps<'a, 'tcx>,
// swap in a new set of IR maps for this function body:
let mut fn_maps = IrMaps::new(ir.tcx);

// Don't run unused pass for #[derive()]
if let FnKind::Method(..) = fk {
let parent = ir.tcx.hir.get_parent(id);
if let Some(hir::map::Node::NodeItem(i)) = ir.tcx.hir.find(parent) {
if i.attrs.iter().any(|a| a.check_name("automatically_derived")) {
return;
}
}
}

debug!("creating fn_maps: {:?}", &fn_maps as *const IrMaps);

let body = ir.tcx.hir.body(body_id);
Expand Down

0 comments on commit 24d410a

Please sign in to comment.