@@ -2176,12 +2176,13 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
2176
2176
let mut parameter_info = Vec :: new ( ) ;
2177
2177
let mut all_candidates = Vec :: new ( ) ;
2178
2178
2179
+ let top_rib_idx = self . ribs [ ValueNS ] . len ( ) - 1 ;
2179
2180
let mut bindings = smallvec ! [ ( PatBoundCtx :: Product , Default :: default ( ) ) ] ;
2180
2181
for ( index, ( pat, ty) ) in inputs. enumerate ( ) {
2181
2182
debug ! ( ?pat, ?ty) ;
2182
2183
self . with_lifetime_rib ( LifetimeRibKind :: Elided ( LifetimeRes :: Infer ) , |this| {
2183
2184
if let Some ( pat) = pat {
2184
- this. resolve_pattern ( pat, PatternSource :: FnParam , & mut bindings) ;
2185
+ this. resolve_pattern ( pat, PatternSource :: FnParam , top_rib_idx , & mut bindings) ;
2185
2186
}
2186
2187
} ) ;
2187
2188
@@ -3445,6 +3446,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3445
3446
Ident :: new ( kw:: SelfLower , span) ,
3446
3447
delegation. id ,
3447
3448
PatternSource :: FnParam ,
3449
+ this. ribs [ ValueNS ] . len ( ) - 1 ,
3448
3450
& mut bindings,
3449
3451
) ;
3450
3452
this. visit_block ( body) ;
@@ -3453,10 +3455,11 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3453
3455
}
3454
3456
3455
3457
fn resolve_params ( & mut self , params : & ' ast [ Param ] ) {
3458
+ let top_rib_idx = self . ribs [ ValueNS ] . len ( ) - 1 ;
3456
3459
let mut bindings = smallvec ! [ ( PatBoundCtx :: Product , Default :: default ( ) ) ] ;
3457
3460
self . with_lifetime_rib ( LifetimeRibKind :: Elided ( LifetimeRes :: Infer ) , |this| {
3458
3461
for Param { pat, .. } in params {
3459
- this. resolve_pattern ( pat, PatternSource :: FnParam , & mut bindings) ;
3462
+ this. resolve_pattern ( pat, PatternSource :: FnParam , top_rib_idx , & mut bindings) ;
3460
3463
}
3461
3464
} ) ;
3462
3465
for Param { ty, .. } in params {
@@ -3674,20 +3677,22 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3674
3677
/// Arising from `source`, resolve a top level pattern.
3675
3678
fn resolve_pattern_top ( & mut self , pat : & ' ast Pat , pat_src : PatternSource ) {
3676
3679
let mut bindings = smallvec ! [ ( PatBoundCtx :: Product , Default :: default ( ) ) ] ;
3677
- self . resolve_pattern ( pat, pat_src, & mut bindings) ;
3680
+ let top_rib_idx = self . ribs [ ValueNS ] . len ( ) - 1 ;
3681
+ self . resolve_pattern ( pat, pat_src, top_rib_idx, & mut bindings) ;
3678
3682
}
3679
3683
3680
3684
fn resolve_pattern (
3681
3685
& mut self ,
3682
3686
pat : & ' ast Pat ,
3683
3687
pat_src : PatternSource ,
3688
+ top_rib_idx : usize ,
3684
3689
bindings : & mut SmallVec < [ ( PatBoundCtx , FxHashSet < Ident > ) ; 1 ] > ,
3685
3690
) {
3686
3691
// We walk the pattern before declaring the pattern's inner bindings,
3687
3692
// so that we avoid resolving a literal expression to a binding defined
3688
3693
// by the pattern.
3689
3694
visit:: walk_pat ( self , pat) ;
3690
- self . resolve_pattern_inner ( pat, pat_src, bindings) ;
3695
+ self . resolve_pattern_inner ( pat, pat_src, top_rib_idx , bindings) ;
3691
3696
// This has to happen *after* we determine which pat_idents are variants:
3692
3697
self . check_consistent_bindings ( pat) ;
3693
3698
}
@@ -3715,6 +3720,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3715
3720
& mut self ,
3716
3721
pat : & ' ast Pat ,
3717
3722
pat_src : PatternSource ,
3723
+ top_rib_idx : usize ,
3718
3724
bindings : & mut SmallVec < [ ( PatBoundCtx , FxHashSet < Ident > ) ; 1 ] > ,
3719
3725
) {
3720
3726
// Visit all direct subpatterns of this pattern.
@@ -3727,7 +3733,9 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3727
3733
let has_sub = sub. is_some ( ) ;
3728
3734
let res = self
3729
3735
. try_resolve_as_non_binding ( pat_src, bmode, ident, has_sub)
3730
- . unwrap_or_else ( || self . fresh_binding ( ident, pat. id , pat_src, bindings) ) ;
3736
+ . unwrap_or_else ( || {
3737
+ self . fresh_binding ( ident, pat. id , pat_src, top_rib_idx, bindings)
3738
+ } ) ;
3731
3739
self . r . record_partial_res ( pat. id , PartialRes :: new ( res) ) ;
3732
3740
self . r . record_pat_span ( pat. id , pat. span ) ;
3733
3741
}
@@ -3758,7 +3766,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3758
3766
// part of the or-pattern internally rejects already bound names.
3759
3767
// For example, `V1(a) | V2(a, a)` and `V1(a, a) | V2(a)` are bad.
3760
3768
bindings. push ( ( PatBoundCtx :: Product , Default :: default ( ) ) ) ;
3761
- self . resolve_pattern_inner ( p, pat_src, bindings) ;
3769
+ self . resolve_pattern_inner ( p, pat_src, top_rib_idx , bindings) ;
3762
3770
// Move up the non-overlapping bindings to the or-pattern.
3763
3771
// Existing bindings just get "merged".
3764
3772
let collected = bindings. pop ( ) . unwrap ( ) . 1 ;
@@ -3775,7 +3783,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3775
3783
}
3776
3784
PatKind :: Guard ( ref subpat, ref cond) => {
3777
3785
self . with_rib ( ValueNS , RibKind :: Normal , |this| {
3778
- this. resolve_pattern_inner ( subpat, pat_src, bindings) ;
3786
+ this. resolve_pattern_inner ( subpat, pat_src, top_rib_idx , bindings) ;
3779
3787
this. resolve_expr ( cond, None ) ;
3780
3788
} ) ;
3781
3789
@@ -3793,6 +3801,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3793
3801
ident : Ident ,
3794
3802
pat_id : NodeId ,
3795
3803
pat_src : PatternSource ,
3804
+ top_rib_idx : usize ,
3796
3805
bindings : & mut SmallVec < [ ( PatBoundCtx , FxHashSet < Ident > ) ; 1 ] > ,
3797
3806
) -> Res {
3798
3807
// Add the binding to the local ribs, if it doesn't already exist in the bindings map.
@@ -3825,18 +3834,23 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3825
3834
bindings. last_mut ( ) . unwrap ( ) . 1 . insert ( ident) ;
3826
3835
}
3827
3836
3828
- if already_bound_or {
3837
+ let res = if already_bound_or {
3829
3838
// `Variant1(a) | Variant2(a)`, ok
3830
3839
// Reuse definition from the first `a`.
3831
- self . innermost_rib_bindings ( ValueNS ) [ & ident]
3840
+ self . ribs [ ValueNS ] [ top_rib_idx ] . bindings [ & ident]
3832
3841
} else {
3833
3842
let res = Res :: Local ( pat_id) ;
3834
3843
if ident_valid {
3835
3844
// A completely fresh binding add to the set if it's valid.
3836
- self . innermost_rib_bindings ( ValueNS ) . insert ( ident, res) ;
3845
+ self . ribs [ ValueNS ] [ top_rib_idx ] . bindings . insert ( ident, res) ;
3837
3846
}
3838
3847
res
3839
- }
3848
+ } ;
3849
+
3850
+ // Record the binding in the innermost rib so guard expressions can use it.
3851
+ self . innermost_rib_bindings ( ValueNS ) . insert ( ident, res) ;
3852
+
3853
+ res
3840
3854
}
3841
3855
3842
3856
fn innermost_rib_bindings ( & mut self , ns : Namespace ) -> & mut IdentMap < Res > {
0 commit comments