@@ -111,6 +111,17 @@ enum PatBoundCtx {
111
111
Or ,
112
112
}
113
113
114
+ /// Tracks bindings resolved within a pattern. This serves two purposes:
115
+ ///
116
+ /// - This tracks when identifiers are bound multiple times within a pattern. In a product context,
117
+ /// this is an error. In an or-pattern, this lets us reuse the same resolution for each instance.
118
+ /// See `fresh_binding` and `resolve_pattern_inner` for more information.
119
+ ///
120
+ /// - The guard expression of a guard pattern may use bindings from within the guard pattern, but
121
+ /// not from elsewhere in the pattern containing it. This allows us to isolate the bindings in the
122
+ /// subpattern to construct the scope for the guard.
123
+ type PatternBindings = SmallVec < [ ( PatBoundCtx , FxHashSet < Ident > ) ; 1 ] > ;
124
+
114
125
/// Does this the item (from the item rib scope) allow generic parameters?
115
126
#[ derive( Copy , Clone , Debug ) ]
116
127
pub ( crate ) enum HasGenericParams {
@@ -3857,7 +3868,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3857
3868
& mut self ,
3858
3869
pat : & ' ast Pat ,
3859
3870
pat_src : PatternSource ,
3860
- bindings : & mut SmallVec < [ ( PatBoundCtx , FxHashSet < Ident > ) ; 1 ] > ,
3871
+ bindings : & mut PatternBindings ,
3861
3872
) {
3862
3873
// We walk the pattern before declaring the pattern's inner bindings,
3863
3874
// so that we avoid resolving a literal expression to a binding defined
@@ -3892,7 +3903,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3892
3903
& mut self ,
3893
3904
pat : & Pat ,
3894
3905
pat_src : PatternSource ,
3895
- bindings : & mut SmallVec < [ ( PatBoundCtx , FxHashSet < Ident > ) ; 1 ] > ,
3906
+ bindings : & mut PatternBindings ,
3896
3907
) {
3897
3908
// Visit all direct subpatterns of this pattern.
3898
3909
pat. walk ( & mut |pat| {
@@ -3988,7 +3999,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3988
3999
ident : Ident ,
3989
4000
pat_id : NodeId ,
3990
4001
pat_src : PatternSource ,
3991
- bindings : & mut SmallVec < [ ( PatBoundCtx , FxHashSet < Ident > ) ; 1 ] > ,
4002
+ bindings : & mut PatternBindings ,
3992
4003
) -> Res {
3993
4004
// Add the binding to the local ribs, if it doesn't already exist in the bindings map.
3994
4005
// (We must not add it if it's in the bindings map because that breaks the assumptions
0 commit comments