@@ -2,7 +2,6 @@ use crate::{ImplTraitContext, ImplTraitPosition, LoweringContext};
22use rustc_ast:: { AttrVec , Block , BlockCheckMode , Expr , Local , LocalKind , Stmt , StmtKind } ;
33use rustc_hir as hir;
44use rustc_session:: parse:: feature_err;
5- use rustc_span:: symbol:: Ident ;
65use rustc_span:: { sym, DesugaringKind } ;
76
87use smallvec:: SmallVec ;
@@ -39,8 +38,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
3938 let hir_id = self . lower_node_id ( s. id ) ;
4039 match & local. kind {
4140 LocalKind :: InitElse ( init, els) => {
42- let ( s, e) = self . lower_let_else ( hir_id, local, init, els, tail) ;
43- stmts. push ( s) ;
41+ let e = self . lower_let_else ( hir_id, local, init, els, tail) ;
4442 expr = Some ( e) ;
4543 // remaining statements are in let-else expression
4644 break ;
@@ -125,36 +123,25 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
125123 init : & Expr ,
126124 els : & Block ,
127125 tail : & [ Stmt ] ,
128- ) -> ( hir :: Stmt < ' hir > , & ' hir hir:: Expr < ' hir > ) {
126+ ) -> & ' hir hir:: Expr < ' hir > {
129127 let ty = local
130128 . ty
131129 . as_ref ( )
132130 . map ( |t| self . lower_ty ( t, ImplTraitContext :: Disallowed ( ImplTraitPosition :: Binding ) ) ) ;
133131 let span = self . lower_span ( local. span ) ;
134132 let span = self . mark_span_with_reason ( DesugaringKind :: LetElse , span, None ) ;
135- let init = Some ( self . lower_expr ( init) ) ;
136- let val = Ident :: with_dummy_span ( sym:: val) ;
137- let ( pat, val_id) =
138- self . pat_ident_binding_mode ( span, val, hir:: BindingAnnotation :: Unannotated ) ;
133+ let init = self . lower_expr ( init) ;
139134 let local_hir_id = self . lower_node_id ( local. id ) ;
140135 self . lower_attrs ( local_hir_id, & local. attrs ) ;
141- // first statement which basically exists for the type annotation
142- let stmt = {
143- let local = self . arena . alloc ( hir:: Local {
136+ let let_expr = {
137+ let lex = self . arena . alloc ( hir:: Let {
144138 hir_id : local_hir_id,
139+ pat : self . lower_pat ( & local. pat ) ,
145140 ty,
146- pat,
147141 init,
148142 span,
149- source : hir:: LocalSource :: Normal ,
150143 } ) ;
151- let kind = hir:: StmtKind :: Local ( local) ;
152- hir:: Stmt { hir_id : stmt_hir_id, kind, span }
153- } ;
154- let let_expr = {
155- let scrutinee = self . expr_ident ( span, val, val_id) ;
156- let let_kind = hir:: ExprKind :: Let ( self . lower_pat ( & local. pat ) , scrutinee, span) ;
157- self . arena . alloc ( self . expr ( span, let_kind, AttrVec :: new ( ) ) )
144+ self . arena . alloc ( self . expr ( span, hir:: ExprKind :: Let ( lex) , AttrVec :: new ( ) ) )
158145 } ;
159146 let then_expr = {
160147 let ( stmts, expr) = self . lower_stmts ( tail) ;
@@ -167,7 +154,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
167154 } ;
168155 self . alias_attrs ( else_expr. hir_id , local_hir_id) ;
169156 let if_expr = self . arena . alloc ( hir:: Expr {
170- hir_id : self . next_id ( ) ,
157+ hir_id : stmt_hir_id ,
171158 span,
172159 kind : hir:: ExprKind :: If ( let_expr, then_expr, Some ( else_expr) ) ,
173160 } ) ;
@@ -180,6 +167,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
180167 )
181168 . emit ( ) ;
182169 }
183- ( stmt , if_expr)
170+ if_expr
184171 }
185172}
0 commit comments