Skip to content

Commit 4fa08e9

Browse files
committed
remove recursive search for items
1 parent 8d9c9b0 commit 4fa08e9

File tree

3 files changed

+15
-43
lines changed

3 files changed

+15
-43
lines changed

compiler/rustc_expand/src/expand.rs

+13-31
Original file line numberDiff line numberDiff line change
@@ -1274,42 +1274,24 @@ impl InvocationCollectorNode for P<ast::Item> {
12741274
res
12751275
}
12761276
fn declared_names(&self) -> Vec<Ident> {
1277-
struct ItemNameVisitor(Vec<Ident>, u8);
1278-
impl Visitor<'_> for ItemNameVisitor {
1279-
fn visit_item(&mut self, i: &ast::Item) {
1280-
self.1 += 1;
1281-
if let ItemKind::Use(ut) = &i.kind {
1282-
fn collect_use_tree_leaves(ut: &ast::UseTree, idents: &mut Vec<Ident>) {
1283-
match &ut.kind {
1284-
ast::UseTreeKind::Glob => {}
1285-
ast::UseTreeKind::Simple(_) => idents.push(ut.ident()),
1286-
ast::UseTreeKind::Nested { items, .. } => {
1287-
for (ut, _) in items {
1288-
collect_use_tree_leaves(ut, idents);
1289-
}
1290-
}
1277+
if let ItemKind::Use(ut) = &self.kind {
1278+
fn collect_use_tree_leaves(ut: &ast::UseTree, idents: &mut Vec<Ident>) {
1279+
match &ut.kind {
1280+
ast::UseTreeKind::Glob => {}
1281+
ast::UseTreeKind::Simple(_) => idents.push(ut.ident()),
1282+
ast::UseTreeKind::Nested { items, .. } => {
1283+
for (ut, _) in items {
1284+
collect_use_tree_leaves(ut, idents);
12911285
}
12921286
}
1293-
1294-
collect_use_tree_leaves(ut, &mut self.0);
1295-
} else {
1296-
self.0.push(i.ident);
12971287
}
1298-
if self.1 < 4 {
1299-
// We only visit up to 3 levels of nesting from this item, like if we were
1300-
// looking at `mod a`, we'd find item `a::b::c`. We have this limit to guard
1301-
// against deeply nested modules behind `cfg` flags, where we could spend
1302-
// significant time collecting this information purely for a potential
1303-
// diagnostic improvement.
1304-
visit::walk_item(self, i);
1305-
}
1306-
self.1 -= 1;
13071288
}
1289+
let mut idents = vec![];
1290+
collect_use_tree_leaves(&ut, &mut idents);
1291+
idents
1292+
} else {
1293+
vec![self.ident]
13081294
}
1309-
1310-
let mut v = ItemNameVisitor(vec![], 0);
1311-
v.visit_item(self);
1312-
v.0
13131295
}
13141296
}
13151297

tests/ui/cfg/diagnostics-reexport.rs

+2-2
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

-10
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:5
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)