remove recursive search for items

This commit is contained in:
Esteban Küber 2024-12-31 22:59:22 +00:00
parent 5210c501bc
commit 4ba4559a9d
3 changed files with 17 additions and 45 deletions

View file

@ -1399,44 +1399,26 @@ impl InvocationCollectorNode for P<ast::Item> {
}
fn declared_idents(&self) -> 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 {
ast::UseTreeKind::Glob => {}
ast::UseTreeKind::Simple(_) => idents.push(ut.ident()),
ast::UseTreeKind::Nested { items, .. } => {
for (ut, _) in items {
collect_use_tree_leaves(ut, idents);
}
}
if let ItemKind::Use(ut) = &self.kind {
fn collect_use_tree_leaves(ut: &ast::UseTree, idents: &mut Vec<Ident>) {
match &ut.kind {
ast::UseTreeKind::Glob => {}
ast::UseTreeKind::Simple(_) => idents.push(ut.ident()),
ast::UseTreeKind::Nested { items, .. } => {
for (ut, _) in items {
collect_use_tree_leaves(ut, idents);
}
}
collect_use_tree_leaves(ut, &mut self.0);
} else {
if let Some(ident) = i.kind.ident() {
self.0.push(ident);
}
}
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 idents = vec![];
collect_use_tree_leaves(&ut, &mut idents);
idents
} else if let Some(ident) = self.kind.ident() {
vec![ident]
} else {
vec![]
}
let mut v = ItemNameVisitor(vec![], 0);
v.visit_item(self);
v.0
}
}

View file

@ -1,7 +1,7 @@
pub mod inner {
#[cfg(false)] //~ NOTE the item is gated here
#[cfg(false)]
mod gone {
pub fn uwu() {} //~ NOTE found an item that was configured out
pub fn uwu() {}
}
#[cfg(false)] //~ NOTE the item is gated here

View file

@ -50,16 +50,6 @@ error[E0425]: cannot find function `uwu` in module `inner`
LL | inner::uwu();
| ^^^ not found in `inner`
|
note: found an item that was configured out
--> $DIR/diagnostics-reexport.rs:4:16
|
LL | pub fn uwu() {}
| ^^^
note: the item is gated here
--> $DIR/diagnostics-reexport.rs:2:11
|
LL | #[cfg(false)]
| ^^^^^
note: found an item that was configured out
--> $DIR/diagnostics-reexport.rs:8:20
|