Skip to content

Commit

Permalink
Add test for collecting items in statics
Browse files Browse the repository at this point in the history
  • Loading branch information
Aatch authored and michaelwoerister committed May 11, 2016
1 parent dace306 commit f4dd4be
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/librustc_trans/collector.rs
Expand Up @@ -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)]
Expand Down Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions 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

0 comments on commit f4dd4be

Please sign in to comment.