Limit how deep we visit items to find cfg'd out names
This commit is contained in:
parent
adcda6ca9a
commit
5210c501bc
1 changed files with 12 additions and 3 deletions
|
|
@ -1399,9 +1399,10 @@ impl InvocationCollectorNode for P<ast::Item> {
|
|||
}
|
||||
|
||||
fn declared_idents(&self) -> Vec<Ident> {
|
||||
struct ItemNameVisitor(Vec<Ident>);
|
||||
struct ItemNameVisitor(Vec<Ident>, u8);
|
||||
impl Visitor<'_> for ItemNameVisitor {
|
||||
fn visit_item(&mut self, i: &ast::Item) {
|
||||
self.1 += 1;
|
||||
if let ItemKind::Use(ut) = &i.kind {
|
||||
fn collect_use_tree_leaves(ut: &ast::UseTree, idents: &mut Vec<Ident>) {
|
||||
match &ut.kind {
|
||||
|
|
@ -1421,11 +1422,19 @@ impl InvocationCollectorNode for P<ast::Item> {
|
|||
self.0.push(ident);
|
||||
}
|
||||
}
|
||||
visit::walk_item(self, i);
|
||||
if self.1 < 4 {
|
||||
// We only visit up to 3 levels of nesting from this item, like if we were
|
||||
// looking at `mod a`, we'd find item `a::b::c`. We have this limit to guard
|
||||
// against deeply nested modules behind `cfg` flags, where we could spend
|
||||
// significant time collecting this information purely for a potential
|
||||
// diagnostic improvement.
|
||||
visit::walk_item(self, i);
|
||||
}
|
||||
self.1 -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
let mut v = ItemNameVisitor(vec![]);
|
||||
let mut v = ItemNameVisitor(vec![], 0);
|
||||
v.visit_item(self);
|
||||
v.0
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue