@@ -69,6 +69,7 @@ impl PatternSource {
69
69
/// Denotes whether the context for the set of already bound bindings is a `Product`
70
70
/// or `Or` context. This is used in e.g., `fresh_binding` and `resolve_pattern_inner`.
71
71
/// See those functions for more information.
72
+ #[ derive( PartialEq ) ]
72
73
enum PatBoundCtx {
73
74
/// A product pattern context, e.g., `Variant(a, b)`.
74
75
Product ,
@@ -1417,21 +1418,12 @@ impl<'a, 'b> LateResolutionVisitor<'a, '_> {
1417
1418
// later passes make about or-patterns.)
1418
1419
let ident = ident. modern_and_legacy ( ) ;
1419
1420
1420
- // Walk outwards the stack of products / or-patterns and
1421
- // find out if the identifier has been bound in any of these.
1422
- let mut already_bound_and = false ;
1423
- let mut already_bound_or = false ;
1424
- for ( is_sum, set) in bindings. iter_mut ( ) . rev ( ) {
1425
- match ( is_sum, set. get ( & ident) . cloned ( ) ) {
1426
- // Already bound in a product pattern, e.g. `(a, a)` which is not allowed.
1427
- ( PatBoundCtx :: Product , Some ( ..) ) => already_bound_and = true ,
1428
- // Already bound in an or-pattern, e.g. `V1(a) | V2(a)`.
1429
- // This is *required* for consistency which is checked later.
1430
- ( PatBoundCtx :: Or , Some ( ..) ) => already_bound_or = true ,
1431
- // Not already bound here.
1432
- _ => { }
1433
- }
1434
- }
1421
+ let mut bound_iter = bindings. iter ( ) . filter ( |( _, set) | set. contains ( & ident) ) ;
1422
+ // Already bound in a product pattern? e.g. `(a, a)` which is not allowed.
1423
+ let already_bound_and = bound_iter. clone ( ) . any ( |( ctx, _) | * ctx == PatBoundCtx :: Product ) ;
1424
+ // Already bound in an or-pattern? e.g. `V1(a) | V2(a)`.
1425
+ // This is *required* for consistency which is checked later.
1426
+ let already_bound_or = bound_iter. any ( |( ctx, _) | * ctx == PatBoundCtx :: Or ) ;
1435
1427
1436
1428
if already_bound_and {
1437
1429
// Overlap in a product pattern somewhere; report an error.
0 commit comments