@@ -750,7 +750,14 @@ impl<'ra: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'r
750750 fn visit_pat ( & mut self , p : & ' ast Pat ) {
751751 let prev = self . diag_metadata . current_pat ;
752752 self . diag_metadata . current_pat = Some ( p) ;
753- visit:: walk_pat ( self , p) ;
753+
754+ match p. kind {
755+ // We visit only the subpattern, allowing the condition to be resolved later in `resolve_pat`.
756+ PatKind :: Guard ( ref subpat, _) => self . visit_pat ( subpat) ,
757+ // Otherwise, we just walk the pattern.
758+ _ => visit:: walk_pat ( self , p) ,
759+ }
760+
754761 self . diag_metadata . current_pat = prev;
755762 }
756763 fn visit_local ( & mut self , local : & ' ast Local ) {
@@ -3737,7 +3744,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
37373744 /// See the implementation and `fresh_binding` for more details.
37383745 fn resolve_pattern_inner (
37393746 & mut self ,
3740- pat : & Pat ,
3747+ pat : & ' ast Pat ,
37413748 pat_src : PatternSource ,
37423749 bindings : & mut SmallVec < [ ( PatBoundCtx , FxHashSet < Ident > ) ; 1 ] > ,
37433750 ) {
@@ -3797,6 +3804,15 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
37973804 // Prevent visiting `ps` as we've already done so above.
37983805 return false ;
37993806 }
3807+ PatKind :: Guard ( ref subpat, ref cond) => {
3808+ self . with_rib ( ValueNS , RibKind :: Normal , |this| {
3809+ this. resolve_pattern_inner ( subpat, pat_src, bindings) ;
3810+ this. resolve_expr ( cond, None ) ;
3811+ } ) ;
3812+
3813+ // Prevent visiting `pat` as we've already done so above.
3814+ return false ;
3815+ }
38003816 _ => { }
38013817 }
38023818 true
0 commit comments