Skip to content

Commit 24d410a

Browse files
Manishearthzofrex
authored andcommitted
Don't run unused variable pass for stuff generated by #[derive()]
1 parent 4ae9488 commit 24d410a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Diff for: src/librustc/middle/liveness.rs

+11
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ impl<'a, 'tcx> Visitor<'tcx> for IrMaps<'a, 'tcx> {
184184
b: hir::BodyId, s: Span, id: NodeId) {
185185
visit_fn(self, fk, fd, b, s, id);
186186
}
187+
187188
fn visit_local(&mut self, l: &'tcx hir::Local) { visit_local(self, l); }
188189
fn visit_expr(&mut self, ex: &'tcx Expr) { visit_expr(self, ex); }
189190
fn visit_arm(&mut self, a: &'tcx hir::Arm) { visit_arm(self, a); }
@@ -361,6 +362,16 @@ fn visit_fn<'a, 'tcx: 'a>(ir: &mut IrMaps<'a, 'tcx>,
361362
// swap in a new set of IR maps for this function body:
362363
let mut fn_maps = IrMaps::new(ir.tcx);
363364

365+
// Don't run unused pass for #[derive()]
366+
if let FnKind::Method(..) = fk {
367+
let parent = ir.tcx.hir.get_parent(id);
368+
if let Some(hir::map::Node::NodeItem(i)) = ir.tcx.hir.find(parent) {
369+
if i.attrs.iter().any(|a| a.check_name("automatically_derived")) {
370+
return;
371+
}
372+
}
373+
}
374+
364375
debug!("creating fn_maps: {:?}", &fn_maps as *const IrMaps);
365376

366377
let body = ir.tcx.hir.body(body_id);

0 commit comments

Comments
 (0)