Rollup merge of #92237 - compiler-errors:issue-92100, r=cjgillot
Visit expressions in-order when resolving pattern bindings [edited:] Visit the pattern's sub-expressions before defining any bindings. Otherwise, we might get into a case where a Lit/Range expression in a pattern has a qpath pointing to a Ident pattern that is defined after it, causing an ICE when lowering to HIR. I have a more detailed explanation in the issue linked. Fixes #92100
This commit is contained in:
commit
f044c6c86c
5 changed files with 50 additions and 1 deletions
|
@ -1603,10 +1603,13 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
|||
pat_src: PatternSource,
|
||||
bindings: &mut SmallVec<[(PatBoundCtx, FxHashSet<Ident>); 1]>,
|
||||
) {
|
||||
// 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);
|
||||
self.resolve_pattern_inner(pat, pat_src, bindings);
|
||||
// This has to happen *after* we determine which pat_idents are variants:
|
||||
self.check_consistent_bindings_top(pat);
|
||||
visit::walk_pat(self, pat);
|
||||
}
|
||||
|
||||
/// Resolve bindings in a pattern. This is a helper to `resolve_pattern`.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue