@@ -485,8 +485,8 @@ type BindingMap = FxHashMap<Ident, BindingInfo>;
485
485
#[ derive( Copy , Clone , PartialEq , Eq , Debug ) ]
486
486
enum PatternSource {
487
487
Match ,
488
- IfLet ,
489
- WhileLet ,
488
+ // FIXME(54883): Consider fusing with `Let` below once let-statements support or-patterns.
489
+ LetExpr ,
490
490
Let ,
491
491
For ,
492
492
FnParam ,
@@ -496,9 +496,7 @@ impl PatternSource {
496
496
fn descr ( self ) -> & ' static str {
497
497
match self {
498
498
PatternSource :: Match => "match binding" ,
499
- PatternSource :: IfLet => "if let binding" ,
500
- PatternSource :: WhileLet => "while let binding" ,
501
- PatternSource :: Let => "let binding" ,
499
+ PatternSource :: Let | PatternSource :: LetExpr => "let binding" ,
502
500
PatternSource :: For => "for binding" ,
503
501
PatternSource :: FnParam => "function parameter" ,
504
502
}
@@ -3057,13 +3055,7 @@ impl<'a> Resolver<'a> {
3057
3055
fn resolve_arm ( & mut self , arm : & Arm ) {
3058
3056
self . ribs [ ValueNS ] . push ( Rib :: new ( NormalRibKind ) ) ;
3059
3057
3060
- let mut bindings_list = FxHashMap :: default ( ) ;
3061
- for pattern in & arm. pats {
3062
- self . resolve_pattern ( & pattern, PatternSource :: Match , & mut bindings_list) ;
3063
- }
3064
-
3065
- // This has to happen *after* we determine which pat_idents are variants.
3066
- self . check_consistent_bindings ( & arm. pats ) ;
3058
+ self . resolve_pats ( & arm. pats , PatternSource :: Match ) ;
3067
3059
3068
3060
if let Some ( ast:: Guard :: If ( ref expr) ) = arm. guard {
3069
3061
self . visit_expr ( expr)
@@ -3073,6 +3065,16 @@ impl<'a> Resolver<'a> {
3073
3065
self . ribs [ ValueNS ] . pop ( ) ;
3074
3066
}
3075
3067
3068
+ /// Arising from `source`, resolve a sequence of patterns (top level or-patterns).
3069
+ fn resolve_pats ( & mut self , pats : & [ P < Pat > ] , source : PatternSource ) {
3070
+ let mut bindings_list = FxHashMap :: default ( ) ;
3071
+ for pat in pats {
3072
+ self . resolve_pattern ( pat, source, & mut bindings_list) ;
3073
+ }
3074
+ // This has to happen *after* we determine which pat_idents are variants
3075
+ self . check_consistent_bindings ( pats) ;
3076
+ }
3077
+
3076
3078
fn resolve_block ( & mut self , block : & Block ) {
3077
3079
debug ! ( "(resolving block) entering block" ) ;
3078
3080
// Move down in the graph, if there's an anonymous module rooted here.
@@ -3151,8 +3153,7 @@ impl<'a> Resolver<'a> {
3151
3153
) ;
3152
3154
}
3153
3155
Some ( ..) if pat_src == PatternSource :: Match ||
3154
- pat_src == PatternSource :: IfLet ||
3155
- pat_src == PatternSource :: WhileLet => {
3156
+ pat_src == PatternSource :: LetExpr => {
3156
3157
// `Variant1(a) | Variant2(a)`, ok
3157
3158
// Reuse definition from the first `a`.
3158
3159
res = self . ribs [ ValueNS ] . last_mut ( ) . unwrap ( ) . bindings [ & ident] ;
@@ -4345,41 +4346,26 @@ impl<'a> Resolver<'a> {
4345
4346
visit:: walk_expr ( self , expr) ;
4346
4347
}
4347
4348
4348
- ExprKind :: IfLet ( ref pats, ref subexpression, ref if_block, ref optional_else) => {
4349
- self . visit_expr ( subexpression) ;
4349
+ ExprKind :: Let ( ref pats, ref scrutinee) => {
4350
+ self . visit_expr ( scrutinee) ;
4351
+ self . resolve_pats ( pats, PatternSource :: LetExpr ) ;
4352
+ }
4350
4353
4354
+ ExprKind :: If ( ref cond, ref then, ref opt_else) => {
4351
4355
self . ribs [ ValueNS ] . push ( Rib :: new ( NormalRibKind ) ) ;
4352
- let mut bindings_list = FxHashMap :: default ( ) ;
4353
- for pat in pats {
4354
- self . resolve_pattern ( pat, PatternSource :: IfLet , & mut bindings_list) ;
4355
- }
4356
- // This has to happen *after* we determine which pat_idents are variants
4357
- self . check_consistent_bindings ( pats) ;
4358
- self . visit_block ( if_block) ;
4356
+ self . visit_expr ( cond) ;
4357
+ self . visit_block ( then) ;
4359
4358
self . ribs [ ValueNS ] . pop ( ) ;
4360
4359
4361
- optional_else . as_ref ( ) . map ( |expr| self . visit_expr ( expr) ) ;
4360
+ opt_else . as_ref ( ) . map ( |expr| self . visit_expr ( expr) ) ;
4362
4361
}
4363
4362
4364
4363
ExprKind :: Loop ( ref block, label) => self . resolve_labeled_block ( label, expr. id , & block) ,
4365
4364
4366
4365
ExprKind :: While ( ref subexpression, ref block, label) => {
4367
4366
self . with_resolved_label ( label, expr. id , |this| {
4368
- this. visit_expr ( subexpression) ;
4369
- this. visit_block ( block) ;
4370
- } ) ;
4371
- }
4372
-
4373
- ExprKind :: WhileLet ( ref pats, ref subexpression, ref block, label) => {
4374
- self . with_resolved_label ( label, expr. id , |this| {
4375
- this. visit_expr ( subexpression) ;
4376
4367
this. ribs [ ValueNS ] . push ( Rib :: new ( NormalRibKind ) ) ;
4377
- let mut bindings_list = FxHashMap :: default ( ) ;
4378
- for pat in pats {
4379
- this. resolve_pattern ( pat, PatternSource :: WhileLet , & mut bindings_list) ;
4380
- }
4381
- // This has to happen *after* we determine which pat_idents are variants.
4382
- this. check_consistent_bindings ( pats) ;
4368
+ this. visit_expr ( subexpression) ;
4383
4369
this. visit_block ( block) ;
4384
4370
this. ribs [ ValueNS ] . pop ( ) ;
4385
4371
} ) ;
0 commit comments