@@ -4447,23 +4447,23 @@ impl<'a> LoweringContext<'a> {
4447
4447
} )
4448
4448
}
4449
4449
4450
+ fn lower_exprs ( & mut self , exprs : & [ AstP < Expr > ] ) -> HirVec < hir:: Expr > {
4451
+ exprs. iter ( ) . map ( |x| self . lower_expr ( x) ) . collect ( )
4452
+ }
4453
+
4450
4454
fn lower_expr ( & mut self , e : & Expr ) -> hir:: Expr {
4451
4455
let kind = match e. node {
4452
4456
ExprKind :: Box ( ref inner) => hir:: ExprKind :: Box ( P ( self . lower_expr ( inner) ) ) ,
4453
- ExprKind :: Array ( ref exprs) => {
4454
- hir:: ExprKind :: Array ( exprs. iter ( ) . map ( |x| self . lower_expr ( x) ) . collect ( ) )
4455
- }
4457
+ ExprKind :: Array ( ref exprs) => hir:: ExprKind :: Array ( self . lower_exprs ( exprs) ) ,
4456
4458
ExprKind :: Repeat ( ref expr, ref count) => {
4457
4459
let expr = P ( self . lower_expr ( expr) ) ;
4458
4460
let count = self . lower_anon_const ( count) ;
4459
4461
hir:: ExprKind :: Repeat ( expr, count)
4460
4462
}
4461
- ExprKind :: Tup ( ref elts) => {
4462
- hir:: ExprKind :: Tup ( elts. iter ( ) . map ( |x| self . lower_expr ( x) ) . collect ( ) )
4463
- }
4463
+ ExprKind :: Tup ( ref elts) => hir:: ExprKind :: Tup ( self . lower_exprs ( elts) ) ,
4464
4464
ExprKind :: Call ( ref f, ref args) => {
4465
4465
let f = P ( self . lower_expr ( f) ) ;
4466
- hir:: ExprKind :: Call ( f, args . iter ( ) . map ( |x| self . lower_expr ( x ) ) . collect ( ) )
4466
+ hir:: ExprKind :: Call ( f, self . lower_exprs ( args ) )
4467
4467
}
4468
4468
ExprKind :: MethodCall ( ref seg, ref args) => {
4469
4469
let hir_seg = P ( self . lower_path_segment (
@@ -4475,7 +4475,7 @@ impl<'a> LoweringContext<'a> {
4475
4475
ImplTraitContext :: disallowed ( ) ,
4476
4476
None ,
4477
4477
) ) ;
4478
- let args = args . iter ( ) . map ( |x| self . lower_expr ( x ) ) . collect ( ) ;
4478
+ let args = self . lower_exprs ( args ) ;
4479
4479
hir:: ExprKind :: MethodCall ( hir_seg, seg. ident . span , args)
4480
4480
}
4481
4481
ExprKind :: Binary ( binop, ref lhs, ref rhs) => {
@@ -5049,17 +5049,9 @@ impl<'a> LoweringContext<'a> {
5049
5049
) ) ;
5050
5050
let arms = hir_vec ! [ pat_arm, break_arm] ;
5051
5051
5052
- P ( self . expr (
5053
- head_sp,
5054
- hir:: ExprKind :: Match (
5055
- next_expr,
5056
- arms,
5057
- hir:: MatchSource :: ForLoopDesugar
5058
- ) ,
5059
- ThinVec :: new ( ) ,
5060
- ) )
5052
+ self . expr_match ( head_sp, next_expr, arms, hir:: MatchSource :: ForLoopDesugar )
5061
5053
} ;
5062
- let match_stmt = self . stmt ( head_sp, hir :: StmtKind :: Expr ( match_expr) ) ;
5054
+ let match_stmt = self . stmt_expr ( head_sp, match_expr) ;
5063
5055
5064
5056
let next_expr = P ( self . expr_ident ( head_sp, next_ident, next_pat_hid) ) ;
5065
5057
@@ -5083,8 +5075,8 @@ impl<'a> LoweringContext<'a> {
5083
5075
) ;
5084
5076
5085
5077
let body_block = self . with_loop_scope ( e. id , |this| this. lower_block ( body, false ) ) ;
5086
- let body_expr = P ( self . expr_block ( body_block, ThinVec :: new ( ) ) ) ;
5087
- let body_stmt = self . stmt ( body. span , hir :: StmtKind :: Expr ( body_expr) ) ;
5078
+ let body_expr = self . expr_block ( body_block, ThinVec :: new ( ) ) ;
5079
+ let body_stmt = self . stmt_expr ( body. span , body_expr) ;
5088
5080
5089
5081
let loop_block = P ( self . block_all (
5090
5082
e. span ,
@@ -5127,8 +5119,10 @@ impl<'a> LoweringContext<'a> {
5127
5119
) ) ;
5128
5120
5129
5121
// This is effectively `{ let _result = ...; _result }`.
5130
- // The construct was introduced in #21984.
5131
- // FIXME(60253): Is this still necessary?
5122
+ // The construct was introduced in #21984 and is necessary to make sure that
5123
+ // temporaries in the `head` expression are dropped and do not leak to the
5124
+ // surrounding scope of the `match` since the `match` is not a terminating scope.
5125
+ //
5132
5126
// Also, add the attributes to the outer returned expr node.
5133
5127
return self . expr_drop_temps ( head_sp, match_expr, e. attrs . clone ( ) )
5134
5128
}
@@ -5254,7 +5248,7 @@ impl<'a> LoweringContext<'a> {
5254
5248
}
5255
5249
5256
5250
fn lower_stmt ( & mut self , s : & Stmt ) -> SmallVec < [ hir:: Stmt ; 1 ] > {
5257
- smallvec ! [ match s. node {
5251
+ let node = match s. node {
5258
5252
StmtKind :: Local ( ref l) => {
5259
5253
let ( l, item_ids) = self . lower_local ( l) ;
5260
5254
let mut ids: SmallVec < [ hir:: Stmt ; 1 ] > = item_ids
@@ -5291,21 +5285,14 @@ impl<'a> LoweringContext<'a> {
5291
5285
} )
5292
5286
. collect ( ) ;
5293
5287
}
5294
- StmtKind :: Expr ( ref e) => {
5295
- hir:: Stmt {
5296
- hir_id: self . lower_node_id( s. id) ,
5297
- node: hir:: StmtKind :: Expr ( P ( self . lower_expr( e) ) ) ,
5298
- span: s. span,
5299
- }
5300
- } ,
5301
- StmtKind :: Semi ( ref e) => {
5302
- hir:: Stmt {
5303
- hir_id: self . lower_node_id( s. id) ,
5304
- node: hir:: StmtKind :: Semi ( P ( self . lower_expr( e) ) ) ,
5305
- span: s. span,
5306
- }
5307
- } ,
5288
+ StmtKind :: Expr ( ref e) => hir:: StmtKind :: Expr ( P ( self . lower_expr ( e) ) ) ,
5289
+ StmtKind :: Semi ( ref e) => hir:: StmtKind :: Semi ( P ( self . lower_expr ( e) ) ) ,
5308
5290
StmtKind :: Mac ( ..) => panic ! ( "Shouldn't exist here" ) ,
5291
+ } ;
5292
+ smallvec ! [ hir:: Stmt {
5293
+ hir_id: self . lower_node_id( s. id) ,
5294
+ node,
5295
+ span: s. span,
5309
5296
} ]
5310
5297
}
5311
5298
@@ -5567,6 +5554,10 @@ impl<'a> LoweringContext<'a> {
5567
5554
hir:: Stmt { span, node, hir_id : self . next_id ( ) }
5568
5555
}
5569
5556
5557
+ fn stmt_expr ( & mut self , span : Span , expr : hir:: Expr ) -> hir:: Stmt {
5558
+ self . stmt ( span, hir:: StmtKind :: Expr ( P ( expr) ) )
5559
+ }
5560
+
5570
5561
fn stmt_let_pat (
5571
5562
& mut self ,
5572
5563
attrs : ThinVec < Attribute > ,
@@ -6060,23 +6051,23 @@ impl<'a> LoweringContext<'a> {
6060
6051
} ;
6061
6052
6062
6053
let match_stmt = {
6063
- let match_expr = P ( self . expr_match (
6054
+ let match_expr = self . expr_match (
6064
6055
span,
6065
6056
poll_expr,
6066
6057
hir_vec ! [ ready_arm, pending_arm] ,
6067
6058
hir:: MatchSource :: AwaitDesugar ,
6068
- ) ) ;
6069
- self . stmt ( span, hir :: StmtKind :: Expr ( match_expr) )
6059
+ ) ;
6060
+ self . stmt_expr ( span, match_expr)
6070
6061
} ;
6071
6062
6072
6063
let yield_stmt = {
6073
6064
let unit = self . expr_unit ( span) ;
6074
- let yield_expr = P ( self . expr (
6065
+ let yield_expr = self . expr (
6075
6066
span,
6076
6067
hir:: ExprKind :: Yield ( P ( unit) , hir:: YieldSource :: Await ) ,
6077
6068
ThinVec :: new ( ) ,
6078
- ) ) ;
6079
- self . stmt ( span, hir :: StmtKind :: Expr ( yield_expr) )
6069
+ ) ;
6070
+ self . stmt_expr ( span, yield_expr)
6080
6071
} ;
6081
6072
6082
6073
let loop_block = P ( self . block_all (
0 commit comments