11use super :: { ImplTraitContext , LoweringContext , ParamMode , ParenthesizedGenericArgs } ;
22
33use rustc:: bug;
4+ use rustc:: middle:: limits:: ensure_sufficient_stack;
45use rustc_ast:: ast:: * ;
56use rustc_ast:: attr;
67use rustc_ast:: ptr:: P as AstP ;
@@ -22,6 +23,37 @@ impl<'hir> LoweringContext<'_, 'hir> {
2223
2324 pub ( super ) fn lower_expr_mut ( & mut self , e : & Expr ) -> hir:: Expr < ' hir > {
2425 let kind = match e. kind {
26+ ExprKind :: Paren ( ref ex) => {
27+ let mut ex = self . lower_expr_mut ( ex) ;
28+ // Include parens in span, but only if it is a super-span.
29+ if e. span . contains ( ex. span ) {
30+ ex. span = e. span ;
31+ }
32+ // Merge attributes into the inner expression.
33+ let mut attrs = e. attrs . clone ( ) ;
34+ attrs. extend :: < Vec < _ > > ( ex. attrs . into ( ) ) ;
35+ ex. attrs = attrs;
36+ return ex;
37+ }
38+
39+ // Desugar `ExprForLoop`
40+ // from: `[opt_ident]: for <pat> in <head> <body>`
41+ ExprKind :: ForLoop ( ref pat, ref head, ref body, opt_label) => {
42+ return self . lower_expr_for ( e, pat, head, body, opt_label) ;
43+ }
44+ _ => ensure_sufficient_stack ( || self . lower_expr_kind ( e) ) ,
45+ } ;
46+
47+ hir:: Expr {
48+ hir_id : self . lower_node_id ( e. id ) ,
49+ kind,
50+ span : e. span ,
51+ attrs : e. attrs . iter ( ) . map ( |a| self . lower_attr ( a) ) . collect :: < Vec < _ > > ( ) . into ( ) ,
52+ }
53+ }
54+
55+ fn lower_expr_kind ( & mut self , e : & Expr ) -> hir:: ExprKind < ' hir > {
56+ match e. kind {
2557 ExprKind :: Box ( ref inner) => hir:: ExprKind :: Box ( self . lower_expr ( inner) ) ,
2658 ExprKind :: Array ( ref exprs) => hir:: ExprKind :: Array ( self . lower_exprs ( exprs) ) ,
2759 ExprKind :: Repeat ( ref expr, ref count) => {
@@ -175,37 +207,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
175207 maybe_expr,
176208 )
177209 }
178- ExprKind :: Paren ( ref ex) => {
179- let mut ex = self . lower_expr_mut ( ex) ;
180- // Include parens in span, but only if it is a super-span.
181- if e. span . contains ( ex. span ) {
182- ex. span = e. span ;
183- }
184- // Merge attributes into the inner expression.
185- let mut attrs = e. attrs . clone ( ) ;
186- attrs. extend :: < Vec < _ > > ( ex. attrs . into ( ) ) ;
187- ex. attrs = attrs;
188- return ex;
189- }
190-
191210 ExprKind :: Yield ( ref opt_expr) => self . lower_expr_yield ( e. span , opt_expr. as_deref ( ) ) ,
192-
193211 ExprKind :: Err => hir:: ExprKind :: Err ,
194-
195- // Desugar `ExprForLoop`
196- // from: `[opt_ident]: for <pat> in <head> <body>`
197- ExprKind :: ForLoop ( ref pat, ref head, ref body, opt_label) => {
198- return self . lower_expr_for ( e, pat, head, body, opt_label) ;
199- }
200212 ExprKind :: Try ( ref sub_expr) => self . lower_expr_try ( e. span , sub_expr) ,
201- ExprKind :: MacCall ( _) => panic ! ( "Shouldn't exist here" ) ,
202- } ;
203213
204- hir:: Expr {
205- hir_id : self . lower_node_id ( e. id ) ,
206- kind,
207- span : e. span ,
208- attrs : e. attrs . iter ( ) . map ( |a| self . lower_attr ( a) ) . collect :: < Vec < _ > > ( ) . into ( ) ,
214+ ExprKind :: ForLoop ( ..) | ExprKind :: Paren ( _) => {
215+ span_bug ! ( e. span, "Should be handled by `lower_expr`" )
216+ }
217+ ExprKind :: MacCall ( _) => span_bug ! ( e. span, "Shouldn't exist here" ) ,
209218 }
210219 }
211220
0 commit comments