@@ -2207,12 +2207,13 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
2207
2207
let mut parameter_info = Vec :: new ( ) ;
2208
2208
let mut all_candidates = Vec :: new ( ) ;
2209
2209
2210
+ let top_rib_idx = self . ribs [ ValueNS ] . len ( ) - 1 ;
2210
2211
let mut bindings = smallvec ! [ ( PatBoundCtx :: Product , Default :: default ( ) ) ] ;
2211
2212
for ( index, ( pat, ty) ) in inputs. enumerate ( ) {
2212
2213
debug ! ( ?pat, ?ty) ;
2213
2214
self . with_lifetime_rib ( LifetimeRibKind :: Elided ( LifetimeRes :: Infer ) , |this| {
2214
2215
if let Some ( pat) = pat {
2215
- this. resolve_pattern ( pat, PatternSource :: FnParam , & mut bindings) ;
2216
+ this. resolve_pattern ( pat, PatternSource :: FnParam , top_rib_idx , & mut bindings) ;
2216
2217
}
2217
2218
} ) ;
2218
2219
@@ -3476,6 +3477,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3476
3477
Ident :: new ( kw:: SelfLower , span) ,
3477
3478
delegation. id ,
3478
3479
PatternSource :: FnParam ,
3480
+ this. ribs [ ValueNS ] . len ( ) - 1 ,
3479
3481
& mut bindings,
3480
3482
) ;
3481
3483
this. visit_block ( body) ;
@@ -3484,10 +3486,11 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3484
3486
}
3485
3487
3486
3488
fn resolve_params ( & mut self , params : & ' ast [ Param ] ) {
3489
+ let top_rib_idx = self . ribs [ ValueNS ] . len ( ) - 1 ;
3487
3490
let mut bindings = smallvec ! [ ( PatBoundCtx :: Product , Default :: default ( ) ) ] ;
3488
3491
self . with_lifetime_rib ( LifetimeRibKind :: Elided ( LifetimeRes :: Infer ) , |this| {
3489
3492
for Param { pat, .. } in params {
3490
- this. resolve_pattern ( pat, PatternSource :: FnParam , & mut bindings) ;
3493
+ this. resolve_pattern ( pat, PatternSource :: FnParam , top_rib_idx , & mut bindings) ;
3491
3494
}
3492
3495
} ) ;
3493
3496
for Param { ty, .. } in params {
@@ -3705,20 +3708,22 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3705
3708
/// Arising from `source`, resolve a top level pattern.
3706
3709
fn resolve_pattern_top ( & mut self , pat : & ' ast Pat , pat_src : PatternSource ) {
3707
3710
let mut bindings = smallvec ! [ ( PatBoundCtx :: Product , Default :: default ( ) ) ] ;
3708
- self . resolve_pattern ( pat, pat_src, & mut bindings) ;
3711
+ let top_rib_idx = self . ribs [ ValueNS ] . len ( ) - 1 ;
3712
+ self . resolve_pattern ( pat, pat_src, top_rib_idx, & mut bindings) ;
3709
3713
}
3710
3714
3711
3715
fn resolve_pattern (
3712
3716
& mut self ,
3713
3717
pat : & ' ast Pat ,
3714
3718
pat_src : PatternSource ,
3719
+ top_rib_idx : usize ,
3715
3720
bindings : & mut SmallVec < [ ( PatBoundCtx , FxHashSet < Ident > ) ; 1 ] > ,
3716
3721
) {
3717
3722
// We walk the pattern before declaring the pattern's inner bindings,
3718
3723
// so that we avoid resolving a literal expression to a binding defined
3719
3724
// by the pattern.
3720
3725
visit:: walk_pat ( self , pat) ;
3721
- self . resolve_pattern_inner ( pat, pat_src, bindings) ;
3726
+ self . resolve_pattern_inner ( pat, pat_src, top_rib_idx , bindings) ;
3722
3727
// This has to happen *after* we determine which pat_idents are variants:
3723
3728
self . check_consistent_bindings ( pat) ;
3724
3729
}
@@ -3746,6 +3751,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3746
3751
& mut self ,
3747
3752
pat : & ' ast Pat ,
3748
3753
pat_src : PatternSource ,
3754
+ top_rib_idx : usize ,
3749
3755
bindings : & mut SmallVec < [ ( PatBoundCtx , FxHashSet < Ident > ) ; 1 ] > ,
3750
3756
) {
3751
3757
// Visit all direct subpatterns of this pattern.
@@ -3758,7 +3764,9 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3758
3764
let has_sub = sub. is_some ( ) ;
3759
3765
let res = self
3760
3766
. try_resolve_as_non_binding ( pat_src, bmode, ident, has_sub)
3761
- . unwrap_or_else ( || self . fresh_binding ( ident, pat. id , pat_src, bindings) ) ;
3767
+ . unwrap_or_else ( || {
3768
+ self . fresh_binding ( ident, pat. id , pat_src, top_rib_idx, bindings)
3769
+ } ) ;
3762
3770
self . r . record_partial_res ( pat. id , PartialRes :: new ( res) ) ;
3763
3771
self . r . record_pat_span ( pat. id , pat. span ) ;
3764
3772
}
@@ -3789,7 +3797,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3789
3797
// part of the or-pattern internally rejects already bound names.
3790
3798
// For example, `V1(a) | V2(a, a)` and `V1(a, a) | V2(a)` are bad.
3791
3799
bindings. push ( ( PatBoundCtx :: Product , Default :: default ( ) ) ) ;
3792
- self . resolve_pattern_inner ( p, pat_src, bindings) ;
3800
+ self . resolve_pattern_inner ( p, pat_src, top_rib_idx , bindings) ;
3793
3801
// Move up the non-overlapping bindings to the or-pattern.
3794
3802
// Existing bindings just get "merged".
3795
3803
let collected = bindings. pop ( ) . unwrap ( ) . 1 ;
@@ -3806,7 +3814,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3806
3814
}
3807
3815
PatKind :: Guard ( ref subpat, ref cond) => {
3808
3816
self . with_rib ( ValueNS , RibKind :: Normal , |this| {
3809
- this. resolve_pattern_inner ( subpat, pat_src, bindings) ;
3817
+ this. resolve_pattern_inner ( subpat, pat_src, top_rib_idx , bindings) ;
3810
3818
this. resolve_expr ( cond, None ) ;
3811
3819
} ) ;
3812
3820
@@ -3824,6 +3832,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3824
3832
ident : Ident ,
3825
3833
pat_id : NodeId ,
3826
3834
pat_src : PatternSource ,
3835
+ top_rib_idx : usize ,
3827
3836
bindings : & mut SmallVec < [ ( PatBoundCtx , FxHashSet < Ident > ) ; 1 ] > ,
3828
3837
) -> Res {
3829
3838
// Add the binding to the local ribs, if it doesn't already exist in the bindings map.
@@ -3856,18 +3865,23 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3856
3865
bindings. last_mut ( ) . unwrap ( ) . 1 . insert ( ident) ;
3857
3866
}
3858
3867
3859
- if already_bound_or {
3868
+ let res = if already_bound_or {
3860
3869
// `Variant1(a) | Variant2(a)`, ok
3861
3870
// Reuse definition from the first `a`.
3862
- self . innermost_rib_bindings ( ValueNS ) [ & ident]
3871
+ self . ribs [ ValueNS ] [ top_rib_idx ] . bindings [ & ident]
3863
3872
} else {
3864
3873
let res = Res :: Local ( pat_id) ;
3865
3874
if ident_valid {
3866
3875
// A completely fresh binding add to the set if it's valid.
3867
- self . innermost_rib_bindings ( ValueNS ) . insert ( ident, res) ;
3876
+ self . ribs [ ValueNS ] [ top_rib_idx ] . bindings . insert ( ident, res) ;
3868
3877
}
3869
3878
res
3870
- }
3879
+ } ;
3880
+
3881
+ // Record the binding in the innermost rib so guard expressions can use it.
3882
+ self . innermost_rib_bindings ( ValueNS ) . insert ( ident, res) ;
3883
+
3884
+ res
3871
3885
}
3872
3886
3873
3887
fn innermost_rib_bindings ( & mut self , ns : Namespace ) -> & mut IdentMap < Res > {
0 commit comments