@@ -68,7 +68,7 @@ impl LoweringContext<'_> {
6868 let ohs = P ( self . lower_expr ( ohs) ) ;
6969 hir:: ExprKind :: AddrOf ( m, ohs)
7070 }
71- ExprKind :: Let ( ref pats , ref scrutinee) => self . lower_expr_let ( e. span , pats , scrutinee) ,
71+ ExprKind :: Let ( ref pat , ref scrutinee) => self . lower_expr_let ( e. span , pat , scrutinee) ,
7272 ExprKind :: If ( ref cond, ref then, ref else_opt) => {
7373 self . lower_expr_if ( e. span , cond, then, else_opt. as_deref ( ) )
7474 }
@@ -227,16 +227,11 @@ impl LoweringContext<'_> {
227227 }
228228 }
229229
230- /// Emit an error and lower `ast::ExprKind::Let(pats , scrutinee)` into:
230+ /// Emit an error and lower `ast::ExprKind::Let(pat , scrutinee)` into:
231231 /// ```rust
232232 /// match scrutinee { pats => true, _ => false }
233233 /// ```
234- fn lower_expr_let (
235- & mut self ,
236- span : Span ,
237- pats : & [ AstP < Pat > ] ,
238- scrutinee : & Expr
239- ) -> hir:: ExprKind {
234+ fn lower_expr_let ( & mut self , span : Span , pat : & Pat , scrutinee : & Expr ) -> hir:: ExprKind {
240235 // If we got here, the `let` expression is not allowed.
241236 self . sess
242237 . struct_span_err ( span, "`let` expressions are not supported here" )
@@ -246,23 +241,23 @@ impl LoweringContext<'_> {
246241
247242 // For better recovery, we emit:
248243 // ```
249- // match scrutinee { pats => true, _ => false }
244+ // match scrutinee { pat => true, _ => false }
250245 // ```
251246 // While this doesn't fully match the user's intent, it has key advantages:
252247 // 1. We can avoid using `abort_if_errors`.
253- // 2. We can typeck both `pats ` and `scrutinee`.
254- // 3. `pats ` is allowed to be refutable.
248+ // 2. We can typeck both `pat ` and `scrutinee`.
249+ // 3. `pat ` is allowed to be refutable.
255250 // 4. The return type of the block is `bool` which seems like what the user wanted.
256251 let scrutinee = self . lower_expr ( scrutinee) ;
257252 let then_arm = {
258- let pats = pats . iter ( ) . map ( |pat| self . lower_pat ( pat) ) . collect ( ) ;
253+ let pat = self . lower_pat_top_hack ( pat) ;
259254 let expr = self . expr_bool ( span, true ) ;
260- self . arm ( pats , P ( expr) )
255+ self . arm ( pat , P ( expr) )
261256 } ;
262257 let else_arm = {
263- let pats = hir_vec ! [ self . pat_wild( span) ] ;
258+ let pat = self . pat_wild ( span) ;
264259 let expr = self . expr_bool ( span, false ) ;
265- self . arm ( pats , P ( expr) )
260+ self . arm ( hir_vec ! [ pat ] , P ( expr) )
266261 } ;
267262 hir:: ExprKind :: Match (
268263 P ( scrutinee) ,
@@ -291,13 +286,12 @@ impl LoweringContext<'_> {
291286 // Handle then + scrutinee:
292287 let then_blk = self . lower_block ( then, false ) ;
293288 let then_expr = self . expr_block ( then_blk, ThinVec :: new ( ) ) ;
294- let ( then_pats , scrutinee, desugar) = match cond. node {
289+ let ( then_pat , scrutinee, desugar) = match cond. node {
295290 // `<pat> => <then>`:
296- ExprKind :: Let ( ref pats , ref scrutinee) => {
291+ ExprKind :: Let ( ref pat , ref scrutinee) => {
297292 let scrutinee = self . lower_expr ( scrutinee) ;
298- let pats = pats. iter ( ) . map ( |pat| self . lower_pat ( pat) ) . collect ( ) ;
299- let desugar = hir:: MatchSource :: IfLetDesugar { contains_else_clause } ;
300- ( pats, scrutinee, desugar)
293+ let pat = self . lower_pat_top_hack ( pat) ;
294+ ( pat, scrutinee, hir:: MatchSource :: IfLetDesugar { contains_else_clause } )
301295 }
302296 // `true => <then>`:
303297 _ => {
@@ -312,13 +306,11 @@ impl LoweringContext<'_> {
312306 // to preserve drop semantics since `if cond { ... }` does not
313307 // let temporaries live outside of `cond`.
314308 let cond = self . expr_drop_temps ( span_block, P ( cond) , ThinVec :: new ( ) ) ;
315-
316- let desugar = hir:: MatchSource :: IfDesugar { contains_else_clause } ;
317- let pats = hir_vec ! [ self . pat_bool( span, true ) ] ;
318- ( pats, cond, desugar)
309+ let pat = self . pat_bool ( span, true ) ;
310+ ( hir_vec ! [ pat] , cond, hir:: MatchSource :: IfDesugar { contains_else_clause } )
319311 }
320312 } ;
321- let then_arm = self . arm ( then_pats , P ( then_expr) ) ;
313+ let then_arm = self . arm ( then_pat , P ( then_expr) ) ;
322314
323315 hir:: ExprKind :: Match ( P ( scrutinee) , vec ! [ then_arm, else_arm] . into ( ) , desugar)
324316 }
@@ -345,8 +337,8 @@ impl LoweringContext<'_> {
345337 // Handle then + scrutinee:
346338 let then_blk = self . lower_block ( body, false ) ;
347339 let then_expr = self . expr_block ( then_blk, ThinVec :: new ( ) ) ;
348- let ( then_pats , scrutinee, desugar, source) = match cond. node {
349- ExprKind :: Let ( ref pats , ref scrutinee) => {
340+ let ( then_pat , scrutinee, desugar, source) = match cond. node {
341+ ExprKind :: Let ( ref pat , ref scrutinee) => {
350342 // to:
351343 //
352344 // [opt_ident]: loop {
@@ -356,9 +348,8 @@ impl LoweringContext<'_> {
356348 // }
357349 // }
358350 let scrutinee = self . with_loop_condition_scope ( |t| t. lower_expr ( scrutinee) ) ;
359- let pats = pats. iter ( ) . map ( |pat| self . lower_pat ( pat) ) . collect ( ) ;
360- let desugar = hir:: MatchSource :: WhileLetDesugar ;
361- ( pats, scrutinee, desugar, hir:: LoopSource :: WhileLet )
351+ let pat = self . lower_pat_top_hack ( pat) ;
352+ ( pat, scrutinee, hir:: MatchSource :: WhileLetDesugar , hir:: LoopSource :: WhileLet )
362353 }
363354 _ => {
364355 // We desugar: `'label: while $cond $body` into:
@@ -383,14 +374,12 @@ impl LoweringContext<'_> {
383374 // to preserve drop semantics since `while cond { ... }` does not
384375 // let temporaries live outside of `cond`.
385376 let cond = self . expr_drop_temps ( span_block, P ( cond) , ThinVec :: new ( ) ) ;
386-
387- let desugar = hir:: MatchSource :: WhileDesugar ;
388377 // `true => <then>`:
389- let pats = hir_vec ! [ self . pat_bool( span, true ) ] ;
390- ( pats , cond, desugar , hir:: LoopSource :: While )
378+ let pat = self . pat_bool ( span, true ) ;
379+ ( hir_vec ! [ pat ] , cond, hir :: MatchSource :: WhileDesugar , hir:: LoopSource :: While )
391380 }
392381 } ;
393- let then_arm = self . arm ( then_pats , P ( then_expr) ) ;
382+ let then_arm = self . arm ( then_pat , P ( then_expr) ) ;
394383
395384 // `match <scrutinee> { ... }`
396385 let match_expr = self . expr_match (
@@ -440,7 +429,7 @@ impl LoweringContext<'_> {
440429 hir:: Arm {
441430 hir_id : self . next_id ( ) ,
442431 attrs : self . lower_attrs ( & arm. attrs ) ,
443- pats : arm . pats . iter ( ) . map ( |x| self . lower_pat ( x ) ) . collect ( ) ,
432+ pats : self . lower_pat_top_hack ( & arm . pat ) ,
444433 guard : match arm. guard {
445434 Some ( ref x) => Some ( hir:: Guard :: If ( P ( self . lower_expr ( x) ) ) ) ,
446435 _ => None ,
@@ -450,6 +439,16 @@ impl LoweringContext<'_> {
450439 }
451440 }
452441
442+ /// HACK(or_patterns; Centril | dlrobertson): For now we don't push down top level or-patterns
443+ /// `p | q` into `hir::PatKind::Or(...)` as post-lowering bits of the compiler are not ready
444+ /// to deal with it. This should by fixed by pushing it down to HIR and then HAIR.
445+ fn lower_pat_top_hack ( & mut self , pat : & Pat ) -> HirVec < P < hir:: Pat > > {
446+ match pat. node {
447+ PatKind :: Or ( ref ps) => ps. iter ( ) . map ( |x| self . lower_pat ( x) ) . collect ( ) ,
448+ _ => hir_vec ! [ self . lower_pat( pat) ] ,
449+ }
450+ }
451+
453452 pub ( super ) fn make_async_expr (
454453 & mut self ,
455454 capture_clause : CaptureBy ,
@@ -1255,7 +1254,6 @@ impl LoweringContext<'_> {
12551254 ThinVec :: from ( attrs. clone ( ) ) ,
12561255 ) ) ;
12571256 let ok_pat = self . pat_ok ( span, val_pat) ;
1258-
12591257 self . arm ( hir_vec ! [ ok_pat] , val_expr)
12601258 } ;
12611259
@@ -1486,7 +1484,10 @@ impl LoweringContext<'_> {
14861484 }
14871485 }
14881486
1489- fn arm ( & mut self , pats : hir:: HirVec < P < hir:: Pat > > , expr : P < hir:: Expr > ) -> hir:: Arm {
1487+ /// HACK(or_patterns; Centril | dlrobertson): For now we don't push down top level or-patterns
1488+ /// `p | q` into `hir::PatKind::Or(...)` as post-lowering bits of the compiler are not ready
1489+ /// to deal with it. This should by fixed by pushing it down to HIR and then HAIR.
1490+ fn arm ( & mut self , pats : HirVec < P < hir:: Pat > > , expr : P < hir:: Expr > ) -> hir:: Arm {
14901491 hir:: Arm {
14911492 hir_id : self . next_id ( ) ,
14921493 attrs : hir_vec ! [ ] ,
0 commit comments