@@ -2,7 +2,6 @@ use crate::{ImplTraitContext, ImplTraitPosition, LoweringContext};
2
2
use rustc_ast:: { AttrVec , Block , BlockCheckMode , Expr , Local , LocalKind , Stmt , StmtKind } ;
3
3
use rustc_hir as hir;
4
4
use rustc_session:: parse:: feature_err;
5
- use rustc_span:: symbol:: Ident ;
6
5
use rustc_span:: { sym, DesugaringKind } ;
7
6
8
7
use smallvec:: SmallVec ;
@@ -39,8 +38,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
39
38
let hir_id = self . lower_node_id ( s. id ) ;
40
39
match & local. kind {
41
40
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) ;
44
42
expr = Some ( e) ;
45
43
// remaining statements are in let-else expression
46
44
break ;
@@ -125,36 +123,25 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
125
123
init : & Expr ,
126
124
els : & Block ,
127
125
tail : & [ Stmt ] ,
128
- ) -> ( hir :: Stmt < ' hir > , & ' hir hir:: Expr < ' hir > ) {
126
+ ) -> & ' hir hir:: Expr < ' hir > {
129
127
let ty = local
130
128
. ty
131
129
. as_ref ( )
132
130
. map ( |t| self . lower_ty ( t, ImplTraitContext :: Disallowed ( ImplTraitPosition :: Binding ) ) ) ;
133
131
let span = self . lower_span ( local. span ) ;
134
132
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) ;
139
134
let local_hir_id = self . lower_node_id ( local. id ) ;
140
135
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 {
144
138
hir_id : local_hir_id,
139
+ pat : self . lower_pat ( & local. pat ) ,
145
140
ty,
146
- pat,
147
141
init,
148
142
span,
149
- source : hir:: LocalSource :: Normal ,
150
143
} ) ;
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 ( ) ) )
158
145
} ;
159
146
let then_expr = {
160
147
let ( stmts, expr) = self . lower_stmts ( tail) ;
@@ -167,7 +154,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
167
154
} ;
168
155
self . alias_attrs ( else_expr. hir_id , local_hir_id) ;
169
156
let if_expr = self . arena . alloc ( hir:: Expr {
170
- hir_id : self . next_id ( ) ,
157
+ hir_id : stmt_hir_id ,
171
158
span,
172
159
kind : hir:: ExprKind :: If ( let_expr, then_expr, Some ( else_expr) ) ,
173
160
} ) ;
@@ -180,6 +167,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
180
167
)
181
168
. emit ( ) ;
182
169
}
183
- ( stmt , if_expr)
170
+ if_expr
184
171
}
185
172
}
0 commit comments