@@ -4738,16 +4738,10 @@ impl<'a> LoweringContext<'a> {
4738
4738
hir:: MatchSource :: ForLoopDesugar ,
4739
4739
) ) ;
4740
4740
4741
- // `{ let _result = ...; _result }`
4742
- // Underscore prevents an `unused_variables` lint if the head diverges.
4743
- let result_ident = self . str_to_ident ( "_result" ) ;
4744
- let ( let_stmt, let_stmt_binding) =
4745
- self . stmt_let ( e. span , false , result_ident, match_expr) ;
4746
-
4747
- let result = P ( self . expr_ident ( e. span , result_ident, let_stmt_binding) ) ;
4748
- let block = P ( self . block_all ( e. span , hir_vec ! [ let_stmt] , Some ( result) ) ) ;
4749
- // Add the attributes to the outer returned expr node.
4750
- return self . expr_block ( block, e. attrs . clone ( ) ) ;
4741
+ // This is effectively `{ let _result = ...; _result }`.
4742
+ // The construct was introduced in #21984.
4743
+ // Also add the attributes to the outer returned expr node.
4744
+ return self . expr_use ( head_sp, match_expr, e. attrs . clone ( ) )
4751
4745
}
4752
4746
4753
4747
// Desugar `ExprKind::Try`
@@ -5117,6 +5111,17 @@ impl<'a> LoweringContext<'a> {
5117
5111
)
5118
5112
}
5119
5113
5114
+ /// Wrap the given `expr` in `hir::ExprKind::Use`.
5115
+ ///
5116
+ /// In terms of drop order, it has the same effect as
5117
+ /// wrapping `expr` in `{ let _t = $expr; _t }` but
5118
+ /// should provide better compile-time performance.
5119
+ ///
5120
+ /// The drop order can be important in e.g. `if expr { .. }`.
5121
+ fn expr_use ( & mut self , span : Span , expr : P < hir:: Expr > , attrs : ThinVec < Attribute > ) -> hir:: Expr {
5122
+ self . expr ( span, hir:: ExprKind :: Use ( expr) , attrs)
5123
+ }
5124
+
5120
5125
fn expr_match (
5121
5126
& mut self ,
5122
5127
span : Span ,
@@ -5172,25 +5177,6 @@ impl<'a> LoweringContext<'a> {
5172
5177
}
5173
5178
}
5174
5179
5175
- fn stmt_let (
5176
- & mut self ,
5177
- sp : Span ,
5178
- mutbl : bool ,
5179
- ident : Ident ,
5180
- ex : P < hir:: Expr > ,
5181
- ) -> ( hir:: Stmt , hir:: HirId ) {
5182
- let ( pat, pat_hid) = if mutbl {
5183
- self . pat_ident_binding_mode ( sp, ident, hir:: BindingAnnotation :: Mutable )
5184
- } else {
5185
- self . pat_ident ( sp, ident)
5186
- } ;
5187
-
5188
- (
5189
- self . stmt_let_pat ( sp, Some ( ex) , pat, hir:: LocalSource :: Normal ) ,
5190
- pat_hid,
5191
- )
5192
- }
5193
-
5194
5180
fn block_expr ( & mut self , expr : P < hir:: Expr > ) -> hir:: Block {
5195
5181
self . block_all ( expr. span , hir:: HirVec :: new ( ) , Some ( expr) )
5196
5182
}
0 commit comments