From dace30659f286206c633fcaaf45d9aa02386a3ac Mon Sep 17 00:00:00 2001 From: James Miller Date: Tue, 10 May 2016 09:00:31 +1200 Subject: [PATCH] Inspect MIR for statics in item collection --- src/librustc_trans/collector.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/librustc_trans/collector.rs b/src/librustc_trans/collector.rs index 0614c29aaed0..f23f931d753a 100644 --- a/src/librustc_trans/collector.rs +++ b/src/librustc_trans/collector.rs @@ -341,7 +341,26 @@ fn collect_items_rec<'a, 'tcx: 'a>(scx: &SharedCrateContext<'a, 'tcx>, let ty = scx.tcx().lookup_item_type(def_id).ty; let ty = glue::get_drop_glue_type(scx.tcx(), ty); neighbors.push(TransItem::DropGlue(DropGlueKind::Ty(ty))); + recursion_depth_reset = None; + + // Scan the MIR in order to find function calls, closures, and + // drop-glue + let mir = errors::expect(ccx.sess().diagnostic(), ccx.get_mir(def_id), + || format!("Could not find MIR for static: {:?}", def_id)); + + let empty_substs = ccx.tcx().mk_substs(Substs::empty()); + let mut visitor = MirNeighborCollector { + ccx: ccx, + mir: &mir, + output: &mut neighbors, + param_substs: empty_substs + }; + + visitor.visit_mir(&mir); + for promoted in &mir.promoted { + visitor.visit_mir(promoted); + } } TransItem::Fn(instance) => { // Keep track of the monomorphization recursion depth