@@ -111,6 +111,17 @@ enum PatBoundCtx {
111111 Or ,
112112}
113113
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+
114125/// Does this the item (from the item rib scope) allow generic parameters?
115126#[ derive( Copy , Clone , Debug ) ]
116127pub ( crate ) enum HasGenericParams {
@@ -3857,7 +3868,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
38573868 & mut self ,
38583869 pat : & ' ast Pat ,
38593870 pat_src : PatternSource ,
3860- bindings : & mut SmallVec < [ ( PatBoundCtx , FxHashSet < Ident > ) ; 1 ] > ,
3871+ bindings : & mut PatternBindings ,
38613872 ) {
38623873 // We walk the pattern before declaring the pattern's inner bindings,
38633874 // 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> {
38923903 & mut self ,
38933904 pat : & Pat ,
38943905 pat_src : PatternSource ,
3895- bindings : & mut SmallVec < [ ( PatBoundCtx , FxHashSet < Ident > ) ; 1 ] > ,
3906+ bindings : & mut PatternBindings ,
38963907 ) {
38973908 // Visit all direct subpatterns of this pattern.
38983909 pat. walk ( & mut |pat| {
@@ -3988,7 +3999,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
39883999 ident : Ident ,
39894000 pat_id : NodeId ,
39904001 pat_src : PatternSource ,
3991- bindings : & mut SmallVec < [ ( PatBoundCtx , FxHashSet < Ident > ) ; 1 ] > ,
4002+ bindings : & mut PatternBindings ,
39924003 ) -> Res {
39934004 // Add the binding to the local ribs, if it doesn't already exist in the bindings map.
39944005 // (We must not add it if it's in the bindings map because that breaks the assumptions
0 commit comments