@@ -4738,16 +4738,10 @@ 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+ // Also add the attributes to the outer returned expr node.
4744+ return self . expr_use ( head_sp, match_expr, e. attrs . clone ( ) )
47514745 }
47524746
47534747 // Desugar `ExprKind::Try`
@@ -5117,6 +5111,17 @@ impl<'a> LoweringContext<'a> {
51175111 )
51185112 }
51195113
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+
51205125 fn expr_match (
51215126 & mut self ,
51225127 span : Span ,
@@ -5172,25 +5177,6 @@ impl<'a> LoweringContext<'a> {
51725177 }
51735178 }
51745179
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-
51945180 fn block_expr ( & mut self , expr : P < hir:: Expr > ) -> hir:: Block {
51955181 self . block_all ( expr. span , hir:: HirVec :: new ( ) , Some ( expr) )
51965182 }
0 commit comments