rustc: don't recurse through nested items in decoded HIR fragments.
This commit is contained in:
parent
f2283a7be0
commit
b01d4891e2
3 changed files with 10 additions and 12 deletions
|
@ -27,6 +27,10 @@ pub struct NodeCollector<'ast> {
|
|||
pub map: Vec<MapEntry<'ast>>,
|
||||
/// The parent of this node
|
||||
pub parent_node: NodeId,
|
||||
/// If true, completely ignore nested items. We set this when loading
|
||||
/// HIR from metadata, since in that case we only want the HIR for
|
||||
/// one specific item (and not the ones nested inside of it).
|
||||
pub ignore_nested_items: bool
|
||||
}
|
||||
|
||||
impl<'ast> NodeCollector<'ast> {
|
||||
|
@ -35,6 +39,7 @@ impl<'ast> NodeCollector<'ast> {
|
|||
krate: krate,
|
||||
map: vec![],
|
||||
parent_node: CRATE_NODE_ID,
|
||||
ignore_nested_items: false
|
||||
};
|
||||
collector.insert_entry(CRATE_NODE_ID, RootCrate);
|
||||
|
||||
|
@ -52,6 +57,7 @@ impl<'ast> NodeCollector<'ast> {
|
|||
krate: krate,
|
||||
map: map,
|
||||
parent_node: parent_node,
|
||||
ignore_nested_items: true
|
||||
};
|
||||
|
||||
assert_eq!(parent_def_path.krate, parent_def_id.krate);
|
||||
|
@ -88,7 +94,9 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
|
|||
/// their outer items.
|
||||
fn visit_nested_item(&mut self, item: ItemId) {
|
||||
debug!("visit_nested_item: {:?}", item);
|
||||
self.visit_item(self.krate.item(item.id))
|
||||
if !self.ignore_nested_items {
|
||||
self.visit_item(self.krate.item(item.id))
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_item(&mut self, i: &'ast Item) {
|
||||
|
|
|
@ -285,15 +285,6 @@ impl<'ast> visit::Visitor for DefCollector<'ast> {
|
|||
|
||||
// We walk the HIR rather than the AST when reading items from metadata.
|
||||
impl<'ast> intravisit::Visitor<'ast> for DefCollector<'ast> {
|
||||
/// Because we want to track parent items and so forth, enable
|
||||
/// deep walking so that we walk nested items in the context of
|
||||
/// their outer items.
|
||||
fn visit_nested_item(&mut self, item_id: hir::ItemId) {
|
||||
debug!("visit_nested_item: {:?}", item_id);
|
||||
let item = self.hir_crate.unwrap().item(item_id.id);
|
||||
self.visit_item(item)
|
||||
}
|
||||
|
||||
fn visit_item(&mut self, i: &'ast hir::Item) {
|
||||
debug!("visit_item: {:?}", i);
|
||||
|
||||
|
|
|
@ -14,11 +14,10 @@ use std::sync::atomic;
|
|||
|
||||
pub const C1: usize = 1;
|
||||
pub const C2: atomic::AtomicUsize = atomic::AtomicUsize::new(0);
|
||||
pub const C3: fn() = foo;
|
||||
pub const C3: fn() = { fn foo() {} foo };
|
||||
pub const C4: usize = C1 * C1 + C1 / C1;
|
||||
pub const C5: &'static usize = &C4;
|
||||
|
||||
pub static S1: usize = 3;
|
||||
pub static S2: atomic::AtomicUsize = atomic::AtomicUsize::new(0);
|
||||
|
||||
fn foo() {}
|
||||
|
|
Loading…
Add table
Reference in a new issue