@@ -258,10 +258,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
258258 ex. span = e. span ;
259259 }
260260 // Merge attributes into the inner expression.
261- let mut attrs: Vec < _ > = e. attrs . iter ( ) . map ( |a| self . lower_attr ( a) ) . collect ( ) ;
262- attrs. extend :: < Vec < _ > > ( ex. attrs . into ( ) ) ;
263- self . attrs [ ex. hir_id ] = & * self . arena . alloc_from_iter ( attrs. iter ( ) . cloned ( ) ) ;
264- ex. attrs = attrs. into ( ) ;
261+ self . attrs [ ex. hir_id ] = & * self . arena . alloc_from_iter (
262+ e. attrs
263+ . iter ( )
264+ . map ( |a| self . lower_attr ( a) )
265+ . chain ( self . attrs [ ex. hir_id ] . iter ( ) . cloned ( ) ) ,
266+ ) ;
265267 return ex;
266268 }
267269
@@ -274,9 +276,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
274276 } ;
275277
276278 let hir_id = self . lower_node_id ( e. id ) ;
277- let attrs = e. attrs . iter ( ) . map ( |a| self . lower_attr ( a) ) . collect :: < Vec < _ > > ( ) ;
278- self . attrs . push_sparse ( hir_id, & * self . arena . alloc_from_iter ( attrs. iter ( ) . cloned ( ) ) ) ;
279- hir:: Expr { hir_id, kind, span : e. span , attrs : attrs. into ( ) }
279+ self . lower_attrs ( hir_id, & e. attrs ) ;
280+ hir:: Expr { hir_id, kind, span : e. span }
280281 } )
281282 }
282283
@@ -684,12 +685,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
684685 span,
685686 Some ( hir:: Movability :: Static ) ,
686687 ) ;
687- let generator = hir:: Expr {
688- hir_id : self . lower_node_id ( closure_node_id) ,
689- kind : generator_kind,
690- span,
691- attrs : ThinVec :: new ( ) ,
692- } ;
688+ let generator =
689+ hir:: Expr { hir_id : self . lower_node_id ( closure_node_id) , kind : generator_kind, span } ;
693690
694691 // `future::from_generator`:
695692 let unstable_span =
@@ -843,7 +840,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
843840 hir_id : loop_hir_id,
844841 kind : hir:: ExprKind :: Loop ( loop_block, None , hir:: LoopSource :: Loop , span) ,
845842 span,
846- attrs : ThinVec :: new ( ) ,
847843 } ) ;
848844
849845 // mut pinned => loop { ... }
@@ -1813,12 +1809,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
18131809 hir:: LoopSource :: ForLoop ,
18141810 e. span . with_hi ( orig_head_span. hi ( ) ) ,
18151811 ) ;
1816- let loop_expr = self . arena . alloc ( hir:: Expr {
1817- hir_id : self . lower_node_id ( e. id ) ,
1818- kind,
1819- span : e. span ,
1820- attrs : ThinVec :: new ( ) ,
1821- } ) ;
1812+ let loop_expr =
1813+ self . arena . alloc ( hir:: Expr { hir_id : self . lower_node_id ( e. id ) , kind, span : e. span } ) ;
18221814
18231815 // `mut iter => { ... }`
18241816 let iter_arm = self . arm ( iter_pat, loop_expr) ;
@@ -2154,8 +2146,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
21542146 attrs : AttrVec ,
21552147 ) -> hir:: Expr < ' hir > {
21562148 let hir_id = self . next_id ( ) ;
2157- self . attrs . push_sparse ( hir_id, & * self . arena . alloc_from_iter ( attrs. iter ( ) . cloned ( ) ) ) ;
2158- hir:: Expr { hir_id, kind, span, attrs }
2149+ self . lower_attrs ( hir_id, & attrs) ;
2150+ hir:: Expr { hir_id, kind, span }
21592151 }
21602152
21612153 fn field ( & mut self , ident : Ident , expr : & ' hir hir:: Expr < ' hir > , span : Span ) -> hir:: Field < ' hir > {
0 commit comments