@@ -758,7 +758,14 @@ impl<'ra: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'r
758
758
fn visit_pat ( & mut self , p : & ' ast Pat ) {
759
759
let prev = self . diag_metadata . current_pat ;
760
760
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
+
762
769
self . diag_metadata . current_pat = prev;
763
770
}
764
771
fn visit_local ( & mut self , local : & ' ast Local ) {
@@ -3751,7 +3758,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3751
3758
/// See the implementation and `fresh_binding` for more details.
3752
3759
fn resolve_pattern_inner (
3753
3760
& mut self ,
3754
- pat : & Pat ,
3761
+ pat : & ' ast Pat ,
3755
3762
pat_src : PatternSource ,
3756
3763
bindings : & mut SmallVec < [ ( PatBoundCtx , FxHashSet < Ident > ) ; 1 ] > ,
3757
3764
) {
@@ -3811,6 +3818,15 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3811
3818
// Prevent visiting `ps` as we've already done so above.
3812
3819
return false ;
3813
3820
}
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
+ }
3814
3830
_ => { }
3815
3831
}
3816
3832
true
0 commit comments