@@ -732,7 +732,14 @@ impl<'ra: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'r
732
732
fn visit_pat ( & mut self , p : & ' ast Pat ) {
733
733
let prev = self . diag_metadata . current_pat ;
734
734
self . diag_metadata . current_pat = Some ( p) ;
735
- visit:: walk_pat ( self , p) ;
735
+
736
+ match p. kind {
737
+ // We visit only the subpattern, allowing the condition to be resolved later in `resolve_pat`.
738
+ PatKind :: Guard ( ref subpat, _) => self . visit_pat ( subpat) ,
739
+ // Otherwise, we just walk the pattern.
740
+ _ => visit:: walk_pat ( self , p) ,
741
+ }
742
+
736
743
self . diag_metadata . current_pat = prev;
737
744
}
738
745
fn visit_local ( & mut self , local : & ' ast Local ) {
@@ -3706,7 +3713,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3706
3713
/// See the implementation and `fresh_binding` for more details.
3707
3714
fn resolve_pattern_inner (
3708
3715
& mut self ,
3709
- pat : & Pat ,
3716
+ pat : & ' ast Pat ,
3710
3717
pat_src : PatternSource ,
3711
3718
bindings : & mut SmallVec < [ ( PatBoundCtx , FxHashSet < Ident > ) ; 1 ] > ,
3712
3719
) {
@@ -3766,6 +3773,15 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3766
3773
// Prevent visiting `ps` as we've already done so above.
3767
3774
return false ;
3768
3775
}
3776
+ PatKind :: Guard ( ref subpat, ref cond) => {
3777
+ self . with_rib ( ValueNS , RibKind :: Normal , |this| {
3778
+ this. resolve_pattern_inner ( subpat, pat_src, bindings) ;
3779
+ this. resolve_expr ( cond, None ) ;
3780
+ } ) ;
3781
+
3782
+ // Prevent visiting `pat` as we've already done so above.
3783
+ return false ;
3784
+ }
3769
3785
_ => { }
3770
3786
}
3771
3787
true
0 commit comments