@@ -4738,16 +4738,11 @@ impl<'a> LoweringContext<'a> {
47384738 hir:: MatchSource :: ForLoopDesugar ,
47394739 ) ) ;
47404740
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+ // FIXME(60253): Is this still necessary?
4744+ // Also, add the attributes to the outer returned expr node.
4745+ return self . expr_use ( head_sp, match_expr, e. attrs . clone ( ) )
47514746 }
47524747
47534748 // Desugar `ExprKind::Try`
@@ -5117,6 +5112,17 @@ impl<'a> LoweringContext<'a> {
51175112 )
51185113 }
51195114
5115+ /// Wrap the given `expr` in `hir::ExprKind::Use`.
5116+ ///
5117+ /// In terms of drop order, it has the same effect as
5118+ /// wrapping `expr` in `{ let _t = $expr; _t }` but
5119+ /// should provide better compile-time performance.
5120+ ///
5121+ /// The drop order can be important in e.g. `if expr { .. }`.
5122+ fn expr_use ( & mut self , span : Span , expr : P < hir:: Expr > , attrs : ThinVec < Attribute > ) -> hir:: Expr {
5123+ self . expr ( span, hir:: ExprKind :: Use ( expr) , attrs)
5124+ }
5125+
51205126 fn expr_match (
51215127 & mut self ,
51225128 span : Span ,
@@ -5172,25 +5178,6 @@ impl<'a> LoweringContext<'a> {
51725178 }
51735179 }
51745180
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-
51945181 fn block_expr ( & mut self , expr : P < hir:: Expr > ) -> hir:: Block {
51955182 self . block_all ( expr. span , hir:: HirVec :: new ( ) , Some ( expr) )
51965183 }
0 commit comments