Skip to content

Commit 3007433

Browse files
committed
add a type alias for the pattern bindings stack
I'll be modifying it in future commits, so I think it's cleanest to abstract it out. Possibly a newtype would be ideal, but for now this is least disruptive.
1 parent 669c1ab commit 3007433

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

‎compiler/rustc_resolve/src/late.rs‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
typePatternBindings = SmallVec<[(PatBoundCtx,FxHashSet<Ident>);1]>;
124+
114125
/// Does this the item (from the item rib scope) allow generic parameters?
115126
#[derive(Copy,Clone,Debug)]
116127
pub(crate)enumHasGenericParams{
@@ -3857,7 +3868,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
38573868
&mutself,
38583869
pat:&'astPat,
38593870
pat_src:PatternSource,
3860-
bindings:&mutSmallVec<[(PatBoundCtx,FxHashSet<Ident>);1]>,
3871+
bindings:&mutPatternBindings,
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
&mutself,
38933904
pat:&Pat,
38943905
pat_src:PatternSource,
3895-
bindings:&mutSmallVec<[(PatBoundCtx,FxHashSet<Ident>);1]>,
3906+
bindings:&mutPatternBindings,
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:&mutSmallVec<[(PatBoundCtx,FxHashSet<Ident>);1]>,
4002+
bindings:&mutPatternBindings,
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

Comments
 (0)