Skip to content

Commit b01d489

Browse files
committed
rustc: don't recurse through nested items in decoded HIR fragments.
1 parent f2283a7 commit b01d489

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

src/librustc/hir/map/collector.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ pub struct NodeCollector<'ast> {
2727
pub map: Vec<MapEntry<'ast>>,
2828
/// The parent of this node
2929
pub parent_node: NodeId,
30+
/// If true, completely ignore nested items. We set this when loading
31+
/// HIR from metadata, since in that case we only want the HIR for
32+
/// one specific item (and not the ones nested inside of it).
33+
pub ignore_nested_items: bool
3034
}
3135

3236
impl<'ast> NodeCollector<'ast> {
@@ -35,6 +39,7 @@ impl<'ast> NodeCollector<'ast> {
3539
krate: krate,
3640
map: vec![],
3741
parent_node: CRATE_NODE_ID,
42+
ignore_nested_items: false
3843
};
3944
collector.insert_entry(CRATE_NODE_ID, RootCrate);
4045

@@ -52,6 +57,7 @@ impl<'ast> NodeCollector<'ast> {
5257
krate: krate,
5358
map: map,
5459
parent_node: parent_node,
60+
ignore_nested_items: true
5561
};
5662

5763
assert_eq!(parent_def_path.krate, parent_def_id.krate);
@@ -88,7 +94,9 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
8894
/// their outer items.
8995
fn visit_nested_item(&mut self, item: ItemId) {
9096
debug!("visit_nested_item: {:?}", item);
91-
self.visit_item(self.krate.item(item.id))
97+
if !self.ignore_nested_items {
98+
self.visit_item(self.krate.item(item.id))
99+
}
92100
}
93101

94102
fn visit_item(&mut self, i: &'ast Item) {

src/librustc/hir/map/def_collector.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,6 @@ impl<'ast> visit::Visitor for DefCollector<'ast> {
285285

286286
// We walk the HIR rather than the AST when reading items from metadata.
287287
impl<'ast> intravisit::Visitor<'ast> for DefCollector<'ast> {
288-
/// Because we want to track parent items and so forth, enable
289-
/// deep walking so that we walk nested items in the context of
290-
/// their outer items.
291-
fn visit_nested_item(&mut self, item_id: hir::ItemId) {
292-
debug!("visit_nested_item: {:?}", item_id);
293-
let item = self.hir_crate.unwrap().item(item_id.id);
294-
self.visit_item(item)
295-
}
296-
297288
fn visit_item(&mut self, i: &'ast hir::Item) {
298289
debug!("visit_item: {:?}", i);
299290

src/test/run-pass/auxiliary/issue-17718-aux.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@ use std::sync::atomic;
1414

1515
pub const C1: usize = 1;
1616
pub const C2: atomic::AtomicUsize = atomic::AtomicUsize::new(0);
17-
pub const C3: fn() = foo;
17+
pub const C3: fn() = { fn foo() {} foo };
1818
pub const C4: usize = C1 * C1 + C1 / C1;
1919
pub const C5: &'static usize = &C4;
2020

2121
pub static S1: usize = 3;
2222
pub static S2: atomic::AtomicUsize = atomic::AtomicUsize::new(0);
2323

24-
fn foo() {}

0 commit comments

Comments
 (0)