about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJames Miller <james@aatch.net>2016-05-10 10:14:41 +1200
committerMichael Woerister <michaelwoerister@posteo.net>2016-05-11 13:59:14 -0400
commitf4dd4be86a9d8310608ee1ae84d33854cce52825 (patch)
treec30c43ae819b9776fdc4ffb6b436ced0eaafbddd
parentdace30659f286206c633fcaaf45d9aa02386a3ac (diff)
downloadrust-f4dd4be86a9d8310608ee1ae84d33854cce52825.tar.gz
rust-f4dd4be86a9d8310608ee1ae84d33854cce52825.zip
Add test for collecting items in statics
-rw-r--r--src/librustc_trans/collector.rs7
-rw-r--r--src/test/codegen-units/item-collection/static-init.rs23
2 files changed, 26 insertions, 4 deletions
diff --git a/src/librustc_trans/collector.rs b/src/librustc_trans/collector.rs
index f23f931d753..3675bf4b8ce 100644
--- a/src/librustc_trans/collector.rs
+++ b/src/librustc_trans/collector.rs
@@ -213,7 +213,6 @@ use meth;
 use monomorphize::{self, Instance};
 use util::nodemap::{FnvHashSet, FnvHashMap, DefIdMap};
 
-use std::hash::{Hash, Hasher};
 use trans_item::{TransItem, type_to_string, def_id_to_string};
 
 #[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
@@ -346,12 +345,12 @@ fn collect_items_rec<'a, 'tcx: 'a>(scx: &SharedCrateContext<'a, 'tcx>,
 
             // 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),
+            let mir = errors::expect(scx.sess().diagnostic(), scx.get_mir(def_id),
                 || format!("Could not find MIR for static: {:?}", def_id));
 
-            let empty_substs = ccx.tcx().mk_substs(Substs::empty());
+            let empty_substs = scx.tcx().mk_substs(Substs::empty());
             let mut visitor = MirNeighborCollector {
-                ccx: ccx,
+                scx: scx,
                 mir: &mir,
                 output: &mut neighbors,
                 param_substs: empty_substs
diff --git a/src/test/codegen-units/item-collection/static-init.rs b/src/test/codegen-units/item-collection/static-init.rs
new file mode 100644
index 00000000000..41c0f46f80b
--- /dev/null
+++ b/src/test/codegen-units/item-collection/static-init.rs
@@ -0,0 +1,23 @@
+// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// compile-flags:-Zprint-trans-items=eager
+
+pub static FN : fn() = foo::<i32>;
+
+pub fn foo<T>() { }
+
+//~ TRANS_ITEM fn static_init::foo[0]<i32>
+//~ TRANS_ITEM static static_init::FN[0]
+
+fn main() { }
+
+//~ TRANS_ITEM fn static_init::main[0]
+//~ TRANS_ITEM drop-glue i8