File tree 1 file changed +12
-3
lines changed
compiler/rustc_expand/src
1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -1274,9 +1274,10 @@ impl InvocationCollectorNode for P<ast::Item> {
1274
1274
res
1275
1275
}
1276
1276
fn declared_names ( & self ) -> Vec < Ident > {
1277
- struct ItemNameVisitor ( Vec < Ident > ) ;
1277
+ struct ItemNameVisitor ( Vec < Ident > , u8 ) ;
1278
1278
impl Visitor < ' _ > for ItemNameVisitor {
1279
1279
fn visit_item ( & mut self , i : & ast:: Item ) {
1280
+ self . 1 += 1 ;
1280
1281
if let ItemKind :: Use ( ut) = & i. kind {
1281
1282
fn collect_use_tree_leaves ( ut : & ast:: UseTree , idents : & mut Vec < Ident > ) {
1282
1283
match & ut. kind {
@@ -1294,11 +1295,19 @@ impl InvocationCollectorNode for P<ast::Item> {
1294
1295
} else {
1295
1296
self . 0 . push ( i. ident ) ;
1296
1297
}
1297
- visit:: walk_item ( self , i) ;
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 ;
1298
1307
}
1299
1308
}
1300
1309
1301
- let mut v = ItemNameVisitor ( vec ! [ ] ) ;
1310
+ let mut v = ItemNameVisitor ( vec ! [ ] , 0 ) ;
1302
1311
v. visit_item ( self ) ;
1303
1312
v. 0
1304
1313
}
You can’t perform that action at this time.
0 commit comments