@@ -26,61 +26,81 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2626 hir:: Block { hir_id, stmts, expr, rules, span : self . lower_span ( b. span ) , targeted_by_break }
2727 }
2828
29- fn lower_stmts (
29+ fn lower_one_stmt (
3030 & mut self ,
31- mut ast_stmts : & [ Stmt ] ,
32- ) -> ( & ' hir [ hir:: Stmt < ' hir > ] , Option < & ' hir hir:: Expr < ' hir > > ) {
33- let mut stmts = SmallVec :: < [ hir:: Stmt < ' hir > ; 8 ] > :: new ( ) ;
34- let mut expr = None ;
35- while let [ s, tail @ ..] = ast_stmts {
36- match & s. kind {
37- StmtKind :: Let ( local) => {
38- let hir_id = self . lower_node_id ( s. id ) ;
39- let local = self . lower_local ( local) ;
40- self . alias_attrs ( hir_id, local. hir_id ) ;
41- let kind = hir:: StmtKind :: Let ( local) ;
42- let span = self . lower_span ( s. span ) ;
43- stmts. push ( hir:: Stmt { hir_id, kind, span } ) ;
44- }
45- StmtKind :: Item ( it) => {
46- stmts. extend ( self . lower_item_ref ( it) . into_iter ( ) . enumerate ( ) . map (
47- |( i, item_id) | {
48- let hir_id = match i {
49- 0 => self . lower_node_id ( s. id ) ,
50- _ => self . next_id ( ) ,
51- } ;
52- let kind = hir:: StmtKind :: Item ( item_id) ;
53- let span = self . lower_span ( s. span ) ;
54- hir:: Stmt { hir_id, kind, span }
55- } ,
56- ) ) ;
57- }
58- StmtKind :: Expr ( e) => {
59- let e = self . lower_expr ( e) ;
60- if tail. is_empty ( ) {
61- expr = Some ( e) ;
62- } else {
63- let hir_id = self . lower_node_id ( s. id ) ;
64- self . alias_attrs ( hir_id, e. hir_id ) ;
65- let kind = hir:: StmtKind :: Expr ( e) ;
31+ s : & Stmt ,
32+ at_tail : Option < & mut Option < & ' hir hir:: Expr < ' hir > > > ,
33+ hir_stmts : & mut impl Extend < hir:: Stmt < ' hir > > ,
34+ ) {
35+ match & s. kind {
36+ StmtKind :: Let ( local) => {
37+ let hir_id = self . lower_node_id ( s. id ) ;
38+ let local = self . lower_local ( local) ;
39+ self . alias_attrs ( hir_id, local. hir_id ) ;
40+ let kind = hir:: StmtKind :: Let ( local) ;
41+ let span = self . lower_span ( s. span ) ;
42+ hir_stmts. extend ( [ hir:: Stmt { hir_id, kind, span } ] ) ;
43+ }
44+ StmtKind :: Item ( it) => {
45+ hir_stmts. extend ( self . lower_item_ref ( it) . into_iter ( ) . enumerate ( ) . map (
46+ |( i, item_id) | {
47+ let hir_id = match i {
48+ 0 => self . lower_node_id ( s. id ) ,
49+ _ => self . next_id ( ) ,
50+ } ;
51+ let kind = hir:: StmtKind :: Item ( item_id) ;
6652 let span = self . lower_span ( s. span ) ;
67- stmts. push ( hir:: Stmt { hir_id, kind, span } ) ;
68- }
69- }
70- StmtKind :: Semi ( e) => {
53+ hir:: Stmt { hir_id, kind, span }
54+ } ,
55+ ) ) ;
56+ }
57+ StmtKind :: Expr ( e) => {
58+ if let Some ( expr) = at_tail {
59+ let e = if self . is_in_init_tail {
60+ let hir_id = self . lower_node_id ( s. id ) ;
61+ let kind = self . lower_implicit_init_tail ( e) ;
62+ self . arena . alloc ( hir:: Expr { hir_id, kind, span : s. span } )
63+ } else {
64+ self . lower_expr ( e)
65+ } ;
66+ * expr = Some ( e) ;
67+ } else {
7168 let e = self . lower_expr ( e) ;
7269 let hir_id = self . lower_node_id ( s. id ) ;
7370 self . alias_attrs ( hir_id, e. hir_id ) ;
74- let kind = hir:: StmtKind :: Semi ( e) ;
71+ let kind = hir:: StmtKind :: Expr ( e) ;
7572 let span = self . lower_span ( s. span ) ;
76- stmts . push ( hir:: Stmt { hir_id, kind, span } ) ;
73+ hir_stmts . extend ( [ hir:: Stmt { hir_id, kind, span } ] ) ;
7774 }
78- StmtKind :: Empty => { }
79- StmtKind :: MacCall ( ..) => panic ! ( "shouldn't exist here" ) ,
8075 }
81- ast_stmts = tail;
76+ StmtKind :: Semi ( e) => {
77+ let e = self . lower_expr ( e) ;
78+ let hir_id = self . lower_node_id ( s. id ) ;
79+ self . alias_attrs ( hir_id, e. hir_id ) ;
80+ let kind = hir:: StmtKind :: Semi ( e) ;
81+ let span = self . lower_span ( s. span ) ;
82+ hir_stmts. extend ( [ hir:: Stmt { hir_id, kind, span } ] ) ;
83+ }
84+ StmtKind :: Empty => { }
85+ StmtKind :: MacCall ( ..) => panic ! ( "shouldn't exist here" ) ,
86+ }
87+ }
88+
89+ fn lower_stmts (
90+ & mut self ,
91+ ast_stmts : & [ Stmt ] ,
92+ ) -> ( & ' hir [ hir:: Stmt < ' hir > ] , Option < & ' hir hir:: Expr < ' hir > > ) {
93+ let mut hir_stmts = SmallVec :: < [ hir:: Stmt < ' hir > ; 8 ] > :: new ( ) ;
94+ let mut expr = None ;
95+ if let [ stmts @ .., tail] = ast_stmts {
96+ self . enter_non_init_tail_lowering ( |this| {
97+ for s in stmts {
98+ this. lower_one_stmt ( s, None , & mut hir_stmts) ;
99+ }
100+ } ) ;
101+ self . lower_one_stmt ( tail, Some ( & mut expr) , & mut hir_stmts) ;
82102 }
83- ( self . arena . alloc_from_iter ( stmts ) , expr)
103+ ( self . arena . alloc_from_iter ( hir_stmts ) , expr)
84104 }
85105
86106 /// Return an `ImplTraitContext` that allows impl trait in bindings if
0 commit comments