@@ -484,8 +484,8 @@ type BindingMap = FxHashMap<Ident, BindingInfo>;
484484#[ derive( Copy , Clone , PartialEq , Eq , Debug ) ]
485485enum PatternSource {
486486 Match ,
487- IfLet ,
488- WhileLet ,
487+ // FIXME(54883): Consider fusing with `Let` below once let-statements support or-patterns.
488+ LetExpr ,
489489 Let ,
490490 For ,
491491 FnParam ,
@@ -495,9 +495,7 @@ impl PatternSource {
495495 fn descr ( self ) -> & ' static str {
496496 match self {
497497 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" ,
501499 PatternSource :: For => "for binding" ,
502500 PatternSource :: FnParam => "function parameter" ,
503501 }
@@ -3093,13 +3091,7 @@ impl<'a> Resolver<'a> {
30933091 fn resolve_arm ( & mut self , arm : & Arm ) {
30943092 self . ribs [ ValueNS ] . push ( Rib :: new ( NormalRibKind ) ) ;
30953093
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 ) ;
31033095
31043096 if let Some ( ast:: Guard :: If ( ref expr) ) = arm. guard {
31053097 self . visit_expr ( expr)
@@ -3109,6 +3101,16 @@ impl<'a> Resolver<'a> {
31093101 self . ribs [ ValueNS ] . pop ( ) ;
31103102 }
31113103
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+
31123114 fn resolve_block ( & mut self , block : & Block ) {
31133115 debug ! ( "(resolving block) entering block" ) ;
31143116 // Move down in the graph, if there's an anonymous module rooted here.
@@ -3187,8 +3189,7 @@ impl<'a> Resolver<'a> {
31873189 ) ;
31883190 }
31893191 Some ( ..) if pat_src == PatternSource :: Match ||
3190- pat_src == PatternSource :: IfLet ||
3191- pat_src == PatternSource :: WhileLet => {
3192+ pat_src == PatternSource :: LetExpr => {
31923193 // `Variant1(a) | Variant2(a)`, ok
31933194 // Reuse definition from the first `a`.
31943195 res = self . ribs [ ValueNS ] . last_mut ( ) . unwrap ( ) . bindings [ & ident] ;
@@ -4409,41 +4410,26 @@ impl<'a> Resolver<'a> {
44094410 visit:: walk_expr ( self , expr) ;
44104411 }
44114412
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+ }
44144417
4418+ ExprKind :: If ( ref cond, ref then, ref opt_else) => {
44154419 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) ;
44234422 self . ribs [ ValueNS ] . pop ( ) ;
44244423
4425- optional_else . as_ref ( ) . map ( |expr| self . visit_expr ( expr) ) ;
4424+ opt_else . as_ref ( ) . map ( |expr| self . visit_expr ( expr) ) ;
44264425 }
44274426
44284427 ExprKind :: Loop ( ref block, label) => self . resolve_labeled_block ( label, expr. id , & block) ,
44294428
44304429 ExprKind :: While ( ref subexpression, ref block, label) => {
44314430 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) ;
44404431 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) ;
44474433 this. visit_block ( block) ;
44484434 this. ribs [ ValueNS ] . pop ( ) ;
44494435 } ) ;
0 commit comments