@@ -2227,12 +2227,13 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
2227
2227
let mut parameter_info = Vec :: new ( ) ;
2228
2228
let mut all_candidates = Vec :: new ( ) ;
2229
2229
2230
+ let top_rib_idx = self . ribs [ ValueNS ] . len ( ) - 1 ;
2230
2231
let mut bindings = smallvec ! [ ( PatBoundCtx :: Product , Default :: default ( ) ) ] ;
2231
2232
for ( index, ( pat, ty) ) in inputs. enumerate ( ) {
2232
2233
debug ! ( ?pat, ?ty) ;
2233
2234
self . with_lifetime_rib ( LifetimeRibKind :: Elided ( LifetimeRes :: Infer ) , |this| {
2234
2235
if let Some ( pat) = pat {
2235
- this. resolve_pattern ( pat, PatternSource :: FnParam , & mut bindings) ;
2236
+ this. resolve_pattern ( pat, PatternSource :: FnParam , top_rib_idx , & mut bindings) ;
2236
2237
}
2237
2238
} ) ;
2238
2239
@@ -3490,6 +3491,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3490
3491
Ident :: new ( kw:: SelfLower , span) ,
3491
3492
delegation. id ,
3492
3493
PatternSource :: FnParam ,
3494
+ this. ribs [ ValueNS ] . len ( ) - 1 ,
3493
3495
& mut bindings,
3494
3496
) ;
3495
3497
this. visit_block ( body) ;
@@ -3498,10 +3500,11 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3498
3500
}
3499
3501
3500
3502
fn resolve_params ( & mut self , params : & ' ast [ Param ] ) {
3503
+ let top_rib_idx = self . ribs [ ValueNS ] . len ( ) - 1 ;
3501
3504
let mut bindings = smallvec ! [ ( PatBoundCtx :: Product , Default :: default ( ) ) ] ;
3502
3505
self . with_lifetime_rib ( LifetimeRibKind :: Elided ( LifetimeRes :: Infer ) , |this| {
3503
3506
for Param { pat, .. } in params {
3504
- this. resolve_pattern ( pat, PatternSource :: FnParam , & mut bindings) ;
3507
+ this. resolve_pattern ( pat, PatternSource :: FnParam , top_rib_idx , & mut bindings) ;
3505
3508
}
3506
3509
} ) ;
3507
3510
for Param { ty, .. } in params {
@@ -3719,20 +3722,22 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3719
3722
/// Arising from `source`, resolve a top level pattern.
3720
3723
fn resolve_pattern_top ( & mut self , pat : & ' ast Pat , pat_src : PatternSource ) {
3721
3724
let mut bindings = smallvec ! [ ( PatBoundCtx :: Product , Default :: default ( ) ) ] ;
3722
- self . resolve_pattern ( pat, pat_src, & mut bindings) ;
3725
+ let top_rib_idx = self . ribs [ ValueNS ] . len ( ) - 1 ;
3726
+ self . resolve_pattern ( pat, pat_src, top_rib_idx, & mut bindings) ;
3723
3727
}
3724
3728
3725
3729
fn resolve_pattern (
3726
3730
& mut self ,
3727
3731
pat : & ' ast Pat ,
3728
3732
pat_src : PatternSource ,
3733
+ top_rib_idx : usize ,
3729
3734
bindings : & mut SmallVec < [ ( PatBoundCtx , FxHashSet < Ident > ) ; 1 ] > ,
3730
3735
) {
3731
3736
// We walk the pattern before declaring the pattern's inner bindings,
3732
3737
// so that we avoid resolving a literal expression to a binding defined
3733
3738
// by the pattern.
3734
3739
visit:: walk_pat ( self , pat) ;
3735
- self . resolve_pattern_inner ( pat, pat_src, bindings) ;
3740
+ self . resolve_pattern_inner ( pat, pat_src, top_rib_idx , bindings) ;
3736
3741
// This has to happen *after* we determine which pat_idents are variants:
3737
3742
self . check_consistent_bindings ( pat) ;
3738
3743
}
@@ -3760,6 +3765,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3760
3765
& mut self ,
3761
3766
pat : & ' ast Pat ,
3762
3767
pat_src : PatternSource ,
3768
+ top_rib_idx : usize ,
3763
3769
bindings : & mut SmallVec < [ ( PatBoundCtx , FxHashSet < Ident > ) ; 1 ] > ,
3764
3770
) {
3765
3771
// Visit all direct subpatterns of this pattern.
@@ -3772,7 +3778,9 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3772
3778
let has_sub = sub. is_some ( ) ;
3773
3779
let res = self
3774
3780
. try_resolve_as_non_binding ( pat_src, bmode, ident, has_sub)
3775
- . unwrap_or_else ( || self . fresh_binding ( ident, pat. id , pat_src, bindings) ) ;
3781
+ . unwrap_or_else ( || {
3782
+ self . fresh_binding ( ident, pat. id , pat_src, top_rib_idx, bindings)
3783
+ } ) ;
3776
3784
self . r . record_partial_res ( pat. id , PartialRes :: new ( res) ) ;
3777
3785
self . r . record_pat_span ( pat. id , pat. span ) ;
3778
3786
}
@@ -3803,7 +3811,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3803
3811
// part of the or-pattern internally rejects already bound names.
3804
3812
// For example, `V1(a) | V2(a, a)` and `V1(a, a) | V2(a)` are bad.
3805
3813
bindings. push ( ( PatBoundCtx :: Product , Default :: default ( ) ) ) ;
3806
- self . resolve_pattern_inner ( p, pat_src, bindings) ;
3814
+ self . resolve_pattern_inner ( p, pat_src, top_rib_idx , bindings) ;
3807
3815
// Move up the non-overlapping bindings to the or-pattern.
3808
3816
// Existing bindings just get "merged".
3809
3817
let collected = bindings. pop ( ) . unwrap ( ) . 1 ;
@@ -3820,7 +3828,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3820
3828
}
3821
3829
PatKind :: Guard ( ref subpat, ref cond) => {
3822
3830
self . with_rib ( ValueNS , RibKind :: Normal , |this| {
3823
- this. resolve_pattern_inner ( subpat, pat_src, bindings) ;
3831
+ this. resolve_pattern_inner ( subpat, pat_src, top_rib_idx , bindings) ;
3824
3832
this. resolve_expr ( cond, None ) ;
3825
3833
} ) ;
3826
3834
@@ -3838,6 +3846,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3838
3846
ident : Ident ,
3839
3847
pat_id : NodeId ,
3840
3848
pat_src : PatternSource ,
3849
+ top_rib_idx : usize ,
3841
3850
bindings : & mut SmallVec < [ ( PatBoundCtx , FxHashSet < Ident > ) ; 1 ] > ,
3842
3851
) -> Res {
3843
3852
// Add the binding to the local ribs, if it doesn't already exist in the bindings map.
@@ -3870,18 +3879,23 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3870
3879
bindings. last_mut ( ) . unwrap ( ) . 1 . insert ( ident) ;
3871
3880
}
3872
3881
3873
- if already_bound_or {
3882
+ let res = if already_bound_or {
3874
3883
// `Variant1(a) | Variant2(a)`, ok
3875
3884
// Reuse definition from the first `a`.
3876
- self . innermost_rib_bindings ( ValueNS ) [ & ident]
3885
+ self . ribs [ ValueNS ] [ top_rib_idx ] . bindings [ & ident]
3877
3886
} else {
3878
3887
let res = Res :: Local ( pat_id) ;
3879
3888
if ident_valid {
3880
3889
// A completely fresh binding add to the set if it's valid.
3881
- self . innermost_rib_bindings ( ValueNS ) . insert ( ident, res) ;
3890
+ self . ribs [ ValueNS ] [ top_rib_idx ] . bindings . insert ( ident, res) ;
3882
3891
}
3883
3892
res
3884
- }
3893
+ } ;
3894
+
3895
+ // Record the binding in the innermost rib so guard expressions can use it.
3896
+ self . innermost_rib_bindings ( ValueNS ) . insert ( ident, res) ;
3897
+
3898
+ res
3885
3899
}
3886
3900
3887
3901
fn innermost_rib_bindings ( & mut self , ns : Namespace ) -> & mut IdentMap < Res > {
0 commit comments