1
1
use crate :: { ImplTraitContext , ImplTraitPosition , LoweringContext } ;
2
- use rustc_ast:: { AttrVec , Block , BlockCheckMode , Expr , Local , LocalKind , Stmt , StmtKind } ;
2
+ use rustc_ast:: { Block , BlockCheckMode , Local , LocalKind , Stmt , StmtKind } ;
3
3
use rustc_hir as hir;
4
4
use rustc_session:: parse:: feature_err;
5
- use rustc_span:: { sym, DesugaringKind } ;
5
+ use rustc_span:: sym;
6
6
7
7
use smallvec:: SmallVec ;
8
8
@@ -36,21 +36,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
36
36
match s. kind {
37
37
StmtKind :: Local ( ref local) => {
38
38
let hir_id = self . lower_node_id ( s. id ) ;
39
- match & local. kind {
40
- LocalKind :: InitElse ( init, els) => {
41
- let e = self . lower_let_else ( hir_id, local, init, els, tail) ;
42
- expr = Some ( e) ;
43
- // remaining statements are in let-else expression
44
- break ;
45
- }
46
- _ => {
47
- let local = self . lower_local ( local) ;
48
- self . alias_attrs ( hir_id, local. hir_id ) ;
49
- let kind = hir:: StmtKind :: Local ( local) ;
50
- let span = self . lower_span ( s. span ) ;
51
- stmts. push ( hir:: Stmt { hir_id, kind, span } ) ;
52
- }
53
- }
39
+ let local = self . lower_local ( local) ;
40
+ self . alias_attrs ( hir_id, local. hir_id ) ;
41
+ let kind = hir:: StmtKind :: Local ( local) ;
42
+ let span = self . lower_span ( s. span ) ;
43
+ stmts. push ( hir:: Stmt { hir_id, kind, span } ) ;
54
44
}
55
45
StmtKind :: Item ( ref it) => {
56
46
stmts. extend ( self . lower_item_ref ( it) . into_iter ( ) . enumerate ( ) . map (
@@ -101,10 +91,24 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
101
91
let init = l. kind . init ( ) . map ( |init| self . lower_expr ( init) ) ;
102
92
let hir_id = self . lower_node_id ( l. id ) ;
103
93
let pat = self . lower_pat ( & l. pat ) ;
94
+ let els = if let LocalKind :: InitElse ( _, els) = & l. kind {
95
+ if !self . tcx . features ( ) . let_else {
96
+ feature_err (
97
+ & self . tcx . sess . parse_sess ,
98
+ sym:: let_else,
99
+ l. span ,
100
+ "`let...else` statements are unstable" ,
101
+ )
102
+ . emit ( ) ;
103
+ }
104
+ Some ( self . lower_block ( els, false ) )
105
+ } else {
106
+ None
107
+ } ;
104
108
let span = self . lower_span ( l. span ) ;
105
109
let source = hir:: LocalSource :: Normal ;
106
110
self . lower_attrs ( hir_id, & l. attrs ) ;
107
- self . arena . alloc ( hir:: Local { hir_id, ty, pat, init, span, source } )
111
+ self . arena . alloc ( hir:: Local { hir_id, ty, pat, init, els , span, source } )
108
112
}
109
113
110
114
fn lower_block_check_mode ( & mut self , b : & BlockCheckMode ) -> hir:: BlockCheckMode {
@@ -115,59 +119,4 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
115
119
}
116
120
}
117
121
}
118
-
119
- fn lower_let_else (
120
- & mut self ,
121
- stmt_hir_id : hir:: HirId ,
122
- local : & Local ,
123
- init : & Expr ,
124
- els : & Block ,
125
- tail : & [ Stmt ] ,
126
- ) -> & ' hir hir:: Expr < ' hir > {
127
- let ty = local
128
- . ty
129
- . as_ref ( )
130
- . map ( |t| self . lower_ty ( t, ImplTraitContext :: Disallowed ( ImplTraitPosition :: Variable ) ) ) ;
131
- let span = self . lower_span ( local. span ) ;
132
- let span = self . mark_span_with_reason ( DesugaringKind :: LetElse , span, None ) ;
133
- let init = self . lower_expr ( init) ;
134
- let local_hir_id = self . lower_node_id ( local. id ) ;
135
- self . lower_attrs ( local_hir_id, & local. attrs ) ;
136
- let let_expr = {
137
- let lex = self . arena . alloc ( hir:: Let {
138
- hir_id : local_hir_id,
139
- pat : self . lower_pat ( & local. pat ) ,
140
- ty,
141
- init,
142
- span,
143
- } ) ;
144
- self . arena . alloc ( self . expr ( span, hir:: ExprKind :: Let ( lex) , AttrVec :: new ( ) ) )
145
- } ;
146
- let then_expr = {
147
- let ( stmts, expr) = self . lower_stmts ( tail) ;
148
- let block = self . block_all ( span, stmts, expr) ;
149
- self . arena . alloc ( self . expr_block ( block, AttrVec :: new ( ) ) )
150
- } ;
151
- let else_expr = {
152
- let block = self . lower_block ( els, false ) ;
153
- self . arena . alloc ( self . expr_block ( block, AttrVec :: new ( ) ) )
154
- } ;
155
- self . alias_attrs ( let_expr. hir_id , local_hir_id) ;
156
- self . alias_attrs ( else_expr. hir_id , local_hir_id) ;
157
- let if_expr = self . arena . alloc ( hir:: Expr {
158
- hir_id : stmt_hir_id,
159
- span,
160
- kind : hir:: ExprKind :: If ( let_expr, then_expr, Some ( else_expr) ) ,
161
- } ) ;
162
- if !self . tcx . features ( ) . let_else {
163
- feature_err (
164
- & self . tcx . sess . parse_sess ,
165
- sym:: let_else,
166
- local. span ,
167
- "`let...else` statements are unstable" ,
168
- )
169
- . emit ( ) ;
170
- }
171
- if_expr
172
- }
173
122
}
0 commit comments