Skip to content

Commit 1b7a0f3

Browse files
committed
remove recursive walk in the visitor
1 parent 82a2046 commit 1b7a0f3

File tree

3 files changed

+4
-24
lines changed

3 files changed

+4
-24
lines changed

compiler/rustc_expand/src/expand.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -1274,10 +1274,9 @@ impl InvocationCollectorNode for P<ast::Item> {
12741274
res
12751275
}
12761276
fn declared_names(&self) -> Vec<Ident> {
1277-
struct ItemNameVisitor(Vec<Ident>, u8);
1277+
struct ItemNameVisitor(Vec<Ident>);
12781278
impl Visitor<'_> for ItemNameVisitor {
12791279
fn visit_item(&mut self, i: &ast::Item) {
1280-
self.1 += 1;
12811280
if let ItemKind::Use(ut) = &i.kind {
12821281
fn collect_use_tree_leaves(ut: &ast::UseTree, idents: &mut Vec<Ident>) {
12831282
match &ut.kind {
@@ -1295,19 +1294,10 @@ impl InvocationCollectorNode for P<ast::Item> {
12951294
} else {
12961295
self.0.push(i.ident);
12971296
}
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;
13071297
}
13081298
}
13091299

1310-
let mut v = ItemNameVisitor(vec![], 0);
1300+
let mut v = ItemNameVisitor(vec![]);
13111301
v.visit_item(self);
13121302
v.0
13131303
}

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)