Skip to content

Commit a972a88

Browse files
committed
perf: skip single_component_path_imports module walk when nothing to lint
1 parent 824aa1f commit a972a88

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

clippy_lints/src/single_component_path_imports.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,24 @@ impl SingleComponentPathImports {
146146
// ```
147147
let mut macros = Vec::new();
148148

149-
let mut import_usage_visitor = ImportUsageVisitor::default();
150149
for item in items {
151150
self.track_uses(item, &mut imports_reused_with_self, &mut single_use_usages, &mut macros);
151+
}
152+
153+
// Only walk the module's AST in search of `self::xxx` paths when there are single
154+
// component imports left to lint, as the visitor recurses into every nested item.
155+
single_use_usages.retain(|usage| !imports_reused_with_self.contains(&usage.name));
156+
if single_use_usages.is_empty() {
157+
return;
158+
}
159+
160+
let mut import_usage_visitor = ImportUsageVisitor::default();
161+
for item in items {
152162
import_usage_visitor.visit_item(item);
153163
}
154164

155165
for usage in single_use_usages {
156-
if !imports_reused_with_self.contains(&usage.name)
157-
&& !import_usage_visitor.imports_referenced_with_self.contains(&usage.name)
158-
{
166+
if !import_usage_visitor.imports_referenced_with_self.contains(&usage.name) {
159167
self.found.entry(usage.item_id).or_default().push(usage);
160168
}
161169
}

0 commit comments

Comments
 (0)