]> git.lizzy.rs Git - rust.git/commitdiff
Register reads on the corrent HIR item
authorJonas Schievink <jonas@schievink.net>
Mon, 11 Jul 2016 15:11:51 +0000 (17:11 +0200)
committerJonas Schievink <jonas@schievink.net>
Mon, 11 Jul 2016 15:11:51 +0000 (17:11 +0200)
src/librustc_trans/trans_item.rs

index ca24a270080ac5daa6027053bf9cf952932e36f1..d3271e6d44c3a71877b948dd30fbcee4f2ac5890 100644 (file)
@@ -111,8 +111,14 @@ fn register_reads(&self, ccx: &CrateContext<'a, 'tcx>) {
                 tcx.map.local_def_id(node_id)
             }
             TransItem::Fn(instance) => {
-                if instance.def.is_local() {
-                    instance.def
+                if let Some(node) = tcx.map.as_local_node_id(instance.def) {
+                    if let hir_map::Node::NodeItem(_) = tcx.map.get(node) {
+                        // This already is a "real" item
+                        instance.def
+                    } else {
+                        // Get the enclosing item and register a read on it
+                        tcx.map.get_parent_did(node)
+                    }
                 } else {
                     // Translating an inlined item from another crate? Don't track anything.
                     return;