Skip to content

Commit f4dd4be

Browse files
Aatchmichaelwoerister
authored andcommitted
Add test for collecting items in statics
1 parent dace306 commit f4dd4be

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

src/librustc_trans/collector.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ use meth;
213213
use monomorphize::{self, Instance};
214214
use util::nodemap::{FnvHashSet, FnvHashMap, DefIdMap};
215215

216-
use std::hash::{Hash, Hasher};
217216
use trans_item::{TransItem, type_to_string, def_id_to_string};
218217

219218
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
@@ -346,12 +345,12 @@ fn collect_items_rec<'a, 'tcx: 'a>(scx: &SharedCrateContext<'a, 'tcx>,
346345

347346
// Scan the MIR in order to find function calls, closures, and
348347
// drop-glue
349-
let mir = errors::expect(ccx.sess().diagnostic(), ccx.get_mir(def_id),
348+
let mir = errors::expect(scx.sess().diagnostic(), scx.get_mir(def_id),
350349
|| format!("Could not find MIR for static: {:?}", def_id));
351350

352-
let empty_substs = ccx.tcx().mk_substs(Substs::empty());
351+
let empty_substs = scx.tcx().mk_substs(Substs::empty());
353352
let mut visitor = MirNeighborCollector {
354-
ccx: ccx,
353+
scx: scx,
355354
mir: &mir,
356355
output: &mut neighbors,
357356
param_substs: empty_substs
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags:-Zprint-trans-items=eager
12+
13+
pub static FN : fn() = foo::<i32>;
14+
15+
pub fn foo<T>() { }
16+
17+
//~ TRANS_ITEM fn static_init::foo[0]<i32>
18+
//~ TRANS_ITEM static static_init::FN[0]
19+
20+
fn main() { }
21+
22+
//~ TRANS_ITEM fn static_init::main[0]
23+
//~ TRANS_ITEM drop-glue i8

0 commit comments

Comments
 (0)