@@ -758,7 +758,14 @@ impl<'ra: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'r
758758 fn visit_pat ( & mut self , p : & ' ast Pat ) {
759759 let prev = self . diag_metadata . current_pat ;
760760 self . diag_metadata . current_pat = Some ( p) ;
761- visit:: walk_pat ( self , p) ;
761+
762+ match p. kind {
763+ // We visit only the subpattern, allowing the condition to be resolved later in `resolve_pat`.
764+ PatKind :: Guard ( ref subpat, _) => self . visit_pat ( subpat) ,
765+ // Otherwise, we just walk the pattern.
766+ _ => visit:: walk_pat ( self , p) ,
767+ }
768+
762769 self . diag_metadata . current_pat = prev;
763770 }
764771 fn visit_local ( & mut self , local : & ' ast Local ) {
@@ -3751,7 +3758,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
37513758 /// See the implementation and `fresh_binding` for more details.
37523759 fn resolve_pattern_inner (
37533760 & mut self ,
3754- pat : & Pat ,
3761+ pat : & ' ast Pat ,
37553762 pat_src : PatternSource ,
37563763 bindings : & mut SmallVec < [ ( PatBoundCtx , FxHashSet < Ident > ) ; 1 ] > ,
37573764 ) {
@@ -3811,6 +3818,15 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
38113818 // Prevent visiting `ps` as we've already done so above.
38123819 return false ;
38133820 }
3821+ PatKind :: Guard ( ref subpat, ref cond) => {
3822+ self . with_rib ( ValueNS , RibKind :: Normal , |this| {
3823+ this. resolve_pattern_inner ( subpat, pat_src, bindings) ;
3824+ this. resolve_expr ( cond, None ) ;
3825+ } ) ;
3826+
3827+ // Prevent visiting `pat` as we've already done so above.
3828+ return false ;
3829+ }
38143830 _ => { }
38153831 }
38163832 true
0 commit comments