@@ -750,7 +750,14 @@ impl<'ra: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'r
750
750
fn visit_pat ( & mut self , p : & ' ast Pat ) {
751
751
let prev = self . diag_metadata . current_pat ;
752
752
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
+
754
761
self . diag_metadata . current_pat = prev;
755
762
}
756
763
fn visit_local ( & mut self , local : & ' ast Local ) {
@@ -3737,7 +3744,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3737
3744
/// See the implementation and `fresh_binding` for more details.
3738
3745
fn resolve_pattern_inner (
3739
3746
& mut self ,
3740
- pat : & Pat ,
3747
+ pat : & ' ast Pat ,
3741
3748
pat_src : PatternSource ,
3742
3749
bindings : & mut SmallVec < [ ( PatBoundCtx , FxHashSet < Ident > ) ; 1 ] > ,
3743
3750
) {
@@ -3797,6 +3804,15 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3797
3804
// Prevent visiting `ps` as we've already done so above.
3798
3805
return false ;
3799
3806
}
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
+ }
3800
3816
_ => { }
3801
3817
}
3802
3818
true
0 commit comments