Skip to content

Commit 4ba4559

Browse files
committed
remove recursive search for items
1 parent 5210c50 commit 4ba4559

File tree

3 files changed

+17
-45
lines changed

3 files changed

+17
-45
lines changed

compiler/rustc_expand/src/expand.rs

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,44 +1399,26 @@ impl InvocationCollectorNode for P<ast::Item> {
13991399
}
14001400

14011401
fn declared_idents(&self) -> Vec<Ident> {
1402-
struct ItemNameVisitor(Vec<Ident>, u8);
1403-
impl Visitor<'_> for ItemNameVisitor {
1404-
fn visit_item(&mut self, i: &ast::Item) {
1405-
self.1 += 1;
1406-
if let ItemKind::Use(ut) = &i.kind {
1407-
fn collect_use_tree_leaves(ut: &ast::UseTree, idents: &mut Vec<Ident>) {
1408-
match &ut.kind {
1409-
ast::UseTreeKind::Glob => {}
1410-
ast::UseTreeKind::Simple(_) => idents.push(ut.ident()),
1411-
ast::UseTreeKind::Nested { items, .. } => {
1412-
for (ut, _) in items {
1413-
collect_use_tree_leaves(ut, idents);
1414-
}
1415-
}
1402+
if let ItemKind::Use(ut) = &self.kind {
1403+
fn collect_use_tree_leaves(ut: &ast::UseTree, idents: &mut Vec<Ident>) {
1404+
match &ut.kind {
1405+
ast::UseTreeKind::Glob => {}
1406+
ast::UseTreeKind::Simple(_) => idents.push(ut.ident()),
1407+
ast::UseTreeKind::Nested { items, .. } => {
1408+
for (ut, _) in items {
1409+
collect_use_tree_leaves(ut, idents);
14161410
}
14171411
}
1418-
1419-
collect_use_tree_leaves(ut, &mut self.0);
1420-
} else {
1421-
if let Some(ident) = i.kind.ident() {
1422-
self.0.push(ident);
1423-
}
1424-
}
1425-
if self.1 < 4 {
1426-
// We only visit up to 3 levels of nesting from this item, like if we were
1427-
// looking at `mod a`, we'd find item `a::b::c`. We have this limit to guard
1428-
// against deeply nested modules behind `cfg` flags, where we could spend
1429-
// significant time collecting this information purely for a potential
1430-
// diagnostic improvement.
1431-
visit::walk_item(self, i);
14321412
}
1433-
self.1 -= 1;
14341413
}
1414+
let mut idents = vec![];
1415+
collect_use_tree_leaves(&ut, &mut idents);
1416+
idents
1417+
} else if let Some(ident) = self.kind.ident() {
1418+
vec![ident]
1419+
} else {
1420+
vec![]
14351421
}
1436-
1437-
let mut v = ItemNameVisitor(vec![], 0);
1438-
v.visit_item(self);
1439-
v.0
14401422
}
14411423
}
14421424

tests/ui/cfg/diagnostics-reexport.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
pub mod inner {
2-
#[cfg(false)] //~ NOTE the item is gated here
2+
#[cfg(false)]
33
mod gone {
4-
pub fn uwu() {} //~ NOTE found an item that was configured out
4+
pub fn uwu() {}
55
}
66

77
#[cfg(false)] //~ NOTE the item is gated here

tests/ui/cfg/diagnostics-reexport.stderr

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,6 @@ error[E0425]: cannot find function `uwu` in module `inner`
5050
LL | inner::uwu();
5151
| ^^^ not found in `inner`
5252
|
53-
note: found an item that was configured out
54-
--> $DIR/diagnostics-reexport.rs:4:16
55-
|
56-
LL | pub fn uwu() {}
57-
| ^^^
58-
note: the item is gated here
59-
--> $DIR/diagnostics-reexport.rs:2:11
60-
|
61-
LL | #[cfg(false)]
62-
| ^^^^^
6353
note: found an item that was configured out
6454
--> $DIR/diagnostics-reexport.rs:8:20
6555
|

0 commit comments

Comments
 (0)