@@ -484,8 +484,8 @@ type BindingMap = FxHashMap<Ident, BindingInfo>;
484
484
#[ derive( Copy , Clone , PartialEq , Eq , Debug ) ]
485
485
enum PatternSource {
486
486
Match ,
487
- IfLet ,
488
- WhileLet ,
487
+ // FIXME(54883): Consider fusing with `Let` below once let-statements support or-patterns.
488
+ LetExpr ,
489
489
Let ,
490
490
For ,
491
491
FnParam ,
@@ -495,9 +495,7 @@ impl PatternSource {
495
495
fn descr ( self ) -> & ' static str {
496
496
match self {
497
497
PatternSource :: Match => "match binding" ,
498
- PatternSource :: IfLet => "if let binding" ,
499
- PatternSource :: WhileLet => "while let binding" ,
500
- PatternSource :: Let => "let binding" ,
498
+ PatternSource :: Let | PatternSource :: LetExpr => "let binding" ,
501
499
PatternSource :: For => "for binding" ,
502
500
PatternSource :: FnParam => "function parameter" ,
503
501
}
@@ -3093,13 +3091,7 @@ impl<'a> Resolver<'a> {
3093
3091
fn resolve_arm ( & mut self , arm : & Arm ) {
3094
3092
self . ribs [ ValueNS ] . push ( Rib :: new ( NormalRibKind ) ) ;
3095
3093
3096
- let mut bindings_list = FxHashMap :: default ( ) ;
3097
- for pattern in & arm. pats {
3098
- self . resolve_pattern ( & pattern, PatternSource :: Match , & mut bindings_list) ;
3099
- }
3100
-
3101
- // This has to happen *after* we determine which pat_idents are variants.
3102
- self . check_consistent_bindings ( & arm. pats ) ;
3094
+ self . resolve_pats ( & arm. pats , PatternSource :: Match ) ;
3103
3095
3104
3096
if let Some ( ast:: Guard :: If ( ref expr) ) = arm. guard {
3105
3097
self . visit_expr ( expr)
@@ -3109,6 +3101,16 @@ impl<'a> Resolver<'a> {
3109
3101
self . ribs [ ValueNS ] . pop ( ) ;
3110
3102
}
3111
3103
3104
+ /// Arising from `source`, resolve a sequence of patterns (top level or-patterns).
3105
+ fn resolve_pats ( & mut self , pats : & [ P < Pat > ] , source : PatternSource ) {
3106
+ let mut bindings_list = FxHashMap :: default ( ) ;
3107
+ for pat in pats {
3108
+ self . resolve_pattern ( pat, source, & mut bindings_list) ;
3109
+ }
3110
+ // This has to happen *after* we determine which pat_idents are variants
3111
+ self . check_consistent_bindings ( pats) ;
3112
+ }
3113
+
3112
3114
fn resolve_block ( & mut self , block : & Block ) {
3113
3115
debug ! ( "(resolving block) entering block" ) ;
3114
3116
// Move down in the graph, if there's an anonymous module rooted here.
@@ -3187,8 +3189,7 @@ impl<'a> Resolver<'a> {
3187
3189
) ;
3188
3190
}
3189
3191
Some ( ..) if pat_src == PatternSource :: Match ||
3190
- pat_src == PatternSource :: IfLet ||
3191
- pat_src == PatternSource :: WhileLet => {
3192
+ pat_src == PatternSource :: LetExpr => {
3192
3193
// `Variant1(a) | Variant2(a)`, ok
3193
3194
// Reuse definition from the first `a`.
3194
3195
res = self . ribs [ ValueNS ] . last_mut ( ) . unwrap ( ) . bindings [ & ident] ;
@@ -4409,41 +4410,26 @@ impl<'a> Resolver<'a> {
4409
4410
visit:: walk_expr ( self , expr) ;
4410
4411
}
4411
4412
4412
- ExprKind :: IfLet ( ref pats, ref subexpression, ref if_block, ref optional_else) => {
4413
- self . visit_expr ( subexpression) ;
4413
+ ExprKind :: Let ( ref pats, ref scrutinee) => {
4414
+ self . visit_expr ( scrutinee) ;
4415
+ self . resolve_pats ( pats, PatternSource :: LetExpr ) ;
4416
+ }
4414
4417
4418
+ ExprKind :: If ( ref cond, ref then, ref opt_else) => {
4415
4419
self . ribs [ ValueNS ] . push ( Rib :: new ( NormalRibKind ) ) ;
4416
- let mut bindings_list = FxHashMap :: default ( ) ;
4417
- for pat in pats {
4418
- self . resolve_pattern ( pat, PatternSource :: IfLet , & mut bindings_list) ;
4419
- }
4420
- // This has to happen *after* we determine which pat_idents are variants
4421
- self . check_consistent_bindings ( pats) ;
4422
- self . visit_block ( if_block) ;
4420
+ self . visit_expr ( cond) ;
4421
+ self . visit_block ( then) ;
4423
4422
self . ribs [ ValueNS ] . pop ( ) ;
4424
4423
4425
- optional_else . as_ref ( ) . map ( |expr| self . visit_expr ( expr) ) ;
4424
+ opt_else . as_ref ( ) . map ( |expr| self . visit_expr ( expr) ) ;
4426
4425
}
4427
4426
4428
4427
ExprKind :: Loop ( ref block, label) => self . resolve_labeled_block ( label, expr. id , & block) ,
4429
4428
4430
4429
ExprKind :: While ( ref subexpression, ref block, label) => {
4431
4430
self . with_resolved_label ( label, expr. id , |this| {
4432
- this. visit_expr ( subexpression) ;
4433
- this. visit_block ( block) ;
4434
- } ) ;
4435
- }
4436
-
4437
- ExprKind :: WhileLet ( ref pats, ref subexpression, ref block, label) => {
4438
- self . with_resolved_label ( label, expr. id , |this| {
4439
- this. visit_expr ( subexpression) ;
4440
4431
this. ribs [ ValueNS ] . push ( Rib :: new ( NormalRibKind ) ) ;
4441
- let mut bindings_list = FxHashMap :: default ( ) ;
4442
- for pat in pats {
4443
- this. resolve_pattern ( pat, PatternSource :: WhileLet , & mut bindings_list) ;
4444
- }
4445
- // This has to happen *after* we determine which pat_idents are variants.
4446
- this. check_consistent_bindings ( pats) ;
4432
+ this. visit_expr ( subexpression) ;
4447
4433
this. visit_block ( block) ;
4448
4434
this. ribs [ ValueNS ] . pop ( ) ;
4449
4435
} ) ;
0 commit comments