diff options
| author | dianne <diannes.gm@gmail.com> | 2025-05-19 18:02:54 -0700 |
|---|---|---|
| committer | dianne <diannes.gm@gmail.com> | 2025-05-19 18:02:54 -0700 |
| commit | ed983c21842be5e84f11b745c0c04ea23baa5509 (patch) | |
| tree | f44a8c3ee71a504c52adf3d5a4f53244398e5c3d /compiler/rustc_resolve/src | |
| parent | e42bbfe1f7c26f8760a99c4b1f27d33aba1040bb (diff) | |
| download | rust-ed983c21842be5e84f11b745c0c04ea23baa5509.tar.gz rust-ed983c21842be5e84f11b745c0c04ea23baa5509.zip | |
only resolve top-level guard patterns' guards once
We resolve guard patterns' guards in `resolve_pattern_inner`, so to avoid resolving them multiple times, we must avoid doing so earlier. To accomplish this, `LateResolutionVisitor::visit_pat` contains a case for guard patterns that avoids visiting their guards while walking patterns. This fixes an ICE due to `visit::walk_pat` being used instead, which meant guards at the top level of a pattern would be visited twice.
Diffstat (limited to 'compiler/rustc_resolve/src')
| -rw-r--r-- | compiler/rustc_resolve/src/late.rs | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 1b682d0cf8a..fd977a8eb6c 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -3901,7 +3901,9 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { // We walk the pattern before declaring the pattern's inner bindings, // so that we avoid resolving a literal expression to a binding defined // by the pattern. - visit::walk_pat(self, pat); + // NB: `Self::visit_pat` must be used rather than `visit::walk_pat` to avoid resolving guard + // patterns' guard expressions multiple times (#141265). + self.visit_pat(pat); self.resolve_pattern_inner(pat, pat_src, bindings); // This has to happen *after* we determine which pat_idents are variants: self.check_consistent_bindings(pat); |
