diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2025-05-28 16:25:15 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2025-05-28 17:02:39 +1000 |
| commit | ac33068f9fdc9d70500325d0f9b4308274fa88a9 (patch) | |
| tree | 31caca71d25f4a854f7273cc674e3a0387999f72 | |
| parent | 7fff1141f2643f986fe1794cd153b65050ee5c3b (diff) | |
| download | rust-ac33068f9fdc9d70500325d0f9b4308274fa88a9.tar.gz rust-ac33068f9fdc9d70500325d0f9b4308274fa88a9.zip | |
Avoid over-counting of `UsePath` in the HIR stats.
| -rw-r--r-- | compiler/rustc_passes/src/input_stats.rs | 10 | ||||
| -rw-r--r-- | tests/ui/stats/input-stats.stderr | 6 |
2 files changed, 11 insertions, 5 deletions
diff --git a/compiler/rustc_passes/src/input_stats.rs b/compiler/rustc_passes/src/input_stats.rs index 71815448172..6852153a2e7 100644 --- a/compiler/rustc_passes/src/input_stats.rs +++ b/compiler/rustc_passes/src/input_stats.rs @@ -426,10 +426,16 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { hir_visit::walk_fn(self, fk, fd, b, id) } - fn visit_use(&mut self, p: &'v hir::UsePath<'v>, hir_id: HirId) { + fn visit_use(&mut self, p: &'v hir::UsePath<'v>, _hir_id: HirId) { // This is `visit_use`, but the type is `Path` so record it that way. self.record("Path", None, p); - hir_visit::walk_use(self, p, hir_id) + // Don't call `hir_visit::walk_use(self, p, hir_id)`: it calls + // `visit_path` up to three times, once for each namespace result in + // `p.res`, by building temporary `Path`s that are not part of the real + // HIR, which causes `p` to be double- or triple-counted. Instead just + // walk the path internals (i.e. the segments) directly. + let hir::Path { span: _, res: _, segments } = *p; + ast_visit::walk_list!(self, visit_path_segment, segments); } fn visit_trait_item(&mut self, ti: &'v hir::TraitItem<'v>) { diff --git a/tests/ui/stats/input-stats.stderr b/tests/ui/stats/input-stats.stderr index d3faa3045f4..58ab1a72556 100644 --- a/tests/ui/stats/input-stats.stderr +++ b/tests/ui/stats/input-stats.stderr @@ -171,8 +171,8 @@ hir-stats - Impl 88 (NN.N%) 1 hir-stats - Trait 88 (NN.N%) 1 hir-stats - Fn 176 (NN.N%) 2 hir-stats - Use 352 (NN.N%) 4 -hir-stats Path 1_240 (NN.N%) 31 40 -hir-stats PathSegment 1_920 (NN.N%) 40 48 +hir-stats Path 1_040 (NN.N%) 26 40 +hir-stats PathSegment 1_776 (NN.N%) 37 48 hir-stats ---------------------------------------------------------------- -hir-stats Total 8_988 180 +hir-stats Total 8_644 172 hir-stats |
