@@ -483,7 +483,7 @@ impl<'a> LoweringContext<'a> {
483483 visit:: walk_crate ( & mut ItemLowerer { lctx : & mut self } , c) ;
484484
485485 let module = self . lower_mod ( & c. module ) ;
486- let attrs = self . lower_attrs ( & c. attrs ) ;
486+ let attrs = self . lower_attrs ( & c. attrs ) . into ( ) ;
487487 let body_ids = body_ids ( & self . bodies ) ;
488488
489489 self . resolver
@@ -1057,21 +1057,32 @@ impl<'a> LoweringContext<'a> {
10571057 }
10581058 }
10591059
1060- fn lower_attrs ( & mut self , attrs : & [ Attribute ] ) -> hir:: HirVec < Attribute > {
1060+ fn lower_attrs ( & mut self , attrs : & [ Attribute ] ) -> Vec < hir:: Attribute > {
10611061 attrs
10621062 . iter ( )
10631063 . map ( |a| self . lower_attr ( a) )
10641064 . collect ( )
10651065 }
10661066
1067- fn lower_attr ( & mut self , attr : & Attribute ) -> Attribute {
1068- // Note that we explicitly do not walk the path. Since we don't really
1069- // lower attributes (we use the AST version) there is nowhere to keep
1070- // the HirIds. We don't actually need HIR version of attributes anyway.
1071- Attribute {
1067+ fn lower_attr ( & mut self , attr : & Attribute ) -> hir:: Attribute {
1068+ hir:: Attribute {
10721069 id : attr. id ,
10731070 style : attr. style ,
1074- path : attr. path . clone ( ) ,
1071+ // HACK(eddyb) manual conversion because `lower_path(_extra)`
1072+ // use `lower_path_segment` and that allocates `ItemLocalId`s.
1073+ path : hir:: Path {
1074+ def : Def :: Err ,
1075+ segments : attr. path . segments . iter ( ) . map ( |segment| {
1076+ hir:: PathSegment :: new (
1077+ segment. ident ,
1078+ None ,
1079+ None ,
1080+ hir:: GenericArgs :: none ( ) ,
1081+ false ,
1082+ )
1083+ } ) . collect ( ) ,
1084+ span : attr. path . span ,
1085+ } ,
10751086 tokens : self . lower_token_stream ( attr. tokens . clone ( ) ) ,
10761087 is_sugared_doc : attr. is_sugared_doc ,
10771088 span : attr. span ,
@@ -1110,7 +1121,7 @@ impl<'a> LoweringContext<'a> {
11101121
11111122 fn lower_arm ( & mut self , arm : & Arm ) -> hir:: Arm {
11121123 hir:: Arm {
1113- attrs : self . lower_attrs ( & arm. attrs ) ,
1124+ attrs : self . lower_attrs ( & arm. attrs ) . into ( ) ,
11141125 pats : arm. pats . iter ( ) . map ( |x| self . lower_pat ( x) ) . collect ( ) ,
11151126 guard : match arm. guard {
11161127 Some ( Guard :: If ( ref x) ) => Some ( hir:: Guard :: If ( P ( self . lower_expr ( x) ) ) ) ,
@@ -1576,7 +1587,7 @@ impl<'a> LoweringContext<'a> {
15761587 Spanned {
15771588 node : hir:: VariantKind {
15781589 name : v. node . ident . name ,
1579- attrs : self . lower_attrs ( & v. node . attrs ) ,
1590+ attrs : self . lower_attrs ( & v. node . attrs ) . into ( ) ,
15801591 data : self . lower_variant_data ( & v. node . data ) ,
15811592 disr_expr : v. node . disr_expr . as_ref ( ) . map ( |e| self . lower_anon_const ( e) ) ,
15821593 } ,
@@ -1967,7 +1978,7 @@ impl<'a> LoweringContext<'a> {
19671978 pat : self . lower_pat ( & l. pat ) ,
19681979 init : l. init . as_ref ( ) . map ( |e| P ( self . lower_expr ( e) ) ) ,
19691980 span : l. span ,
1970- attrs : l. attrs . clone ( ) ,
1981+ attrs : self . lower_attrs ( & l. attrs ) . into ( ) ,
19711982 source : hir:: LocalSource :: Normal ,
19721983 } ) , ids)
19731984 }
@@ -2410,7 +2421,7 @@ impl<'a> LoweringContext<'a> {
24102421 name : param_name,
24112422 span : lt. span ,
24122423 pure_wrt_drop : attr:: contains_name ( & param. attrs , "may_dangle" ) ,
2413- attrs : self . lower_attrs ( & param. attrs ) ,
2424+ attrs : self . lower_attrs ( & param. attrs ) . into ( ) ,
24142425 bounds,
24152426 kind : hir:: GenericParamKind :: Lifetime {
24162427 kind : hir:: LifetimeParamKind :: Explicit ,
@@ -2443,7 +2454,7 @@ impl<'a> LoweringContext<'a> {
24432454 id : self . lower_node_id ( param. id ) . node_id ,
24442455 name : hir:: ParamName :: Plain ( ident) ,
24452456 pure_wrt_drop : attr:: contains_name ( & param. attrs , "may_dangle" ) ,
2446- attrs : self . lower_attrs ( & param. attrs ) ,
2457+ attrs : self . lower_attrs ( & param. attrs ) . into ( ) ,
24472458 bounds,
24482459 span : ident. span ,
24492460 kind : hir:: GenericParamKind :: Type {
@@ -2667,7 +2678,7 @@ impl<'a> LoweringContext<'a> {
26672678 } ,
26682679 vis : self . lower_visibility ( & f. vis , None ) ,
26692680 ty : self . lower_ty ( & f. ty , ImplTraitContext :: disallowed ( ) ) ,
2670- attrs : self . lower_attrs ( & f. attrs ) ,
2681+ attrs : self . lower_attrs ( & f. attrs ) . into ( ) ,
26712682 }
26722683 }
26732684
@@ -2750,7 +2761,7 @@ impl<'a> LoweringContext<'a> {
27502761 & mut self ,
27512762 id : NodeId ,
27522763 name : & mut Name ,
2753- attrs : & hir:: HirVec < Attribute > ,
2764+ attrs : & hir:: HirVec < hir :: Attribute > ,
27542765 vis : & mut hir:: Visibility ,
27552766 i : & ItemKind ,
27562767 ) -> hir:: ItemKind {
@@ -2956,7 +2967,7 @@ impl<'a> LoweringContext<'a> {
29562967 id : NodeId ,
29572968 vis : & mut hir:: Visibility ,
29582969 name : & mut Name ,
2959- attrs : & hir:: HirVec < Attribute > ,
2970+ attrs : & hir:: HirVec < hir :: Attribute > ,
29602971 ) -> hir:: ItemKind {
29612972 debug ! ( "lower_use_tree(tree={:?})" , tree) ;
29622973 debug ! ( "lower_use_tree: vis = {:?}" , vis) ;
@@ -3257,7 +3268,7 @@ impl<'a> LoweringContext<'a> {
32573268 id : node_id,
32583269 hir_id,
32593270 ident : i. ident ,
3260- attrs : self . lower_attrs ( & i. attrs ) ,
3271+ attrs : self . lower_attrs ( & i. attrs ) . into ( ) ,
32613272 generics,
32623273 node,
32633274 span : i. span ,
@@ -3333,7 +3344,7 @@ impl<'a> LoweringContext<'a> {
33333344 id : node_id,
33343345 hir_id,
33353346 ident : i. ident ,
3336- attrs : self . lower_attrs ( & i. attrs ) ,
3347+ attrs : self . lower_attrs ( & i. attrs ) . into ( ) ,
33373348 generics,
33383349 vis : self . lower_visibility ( & i. vis , None ) ,
33393350 defaultness : self . lower_defaultness ( i. defaultness , true /* [1] */ ) ,
@@ -3427,7 +3438,7 @@ impl<'a> LoweringContext<'a> {
34273438 pub fn lower_item ( & mut self , i : & Item ) -> Option < hir:: Item > {
34283439 let mut name = i. ident . name ;
34293440 let mut vis = self . lower_visibility ( & i. vis , None ) ;
3430- let attrs = self . lower_attrs ( & i. attrs ) ;
3441+ let attrs = self . lower_attrs ( & i. attrs ) . into ( ) ;
34313442 if let ItemKind :: MacroDef ( ref def) = i. node {
34323443 if !def. legacy || attr:: contains_name ( & i. attrs , "macro_export" ) ||
34333444 attr:: contains_name ( & i. attrs , "rustc_doc_only_macro" ) {
@@ -3466,7 +3477,7 @@ impl<'a> LoweringContext<'a> {
34663477 hir:: ForeignItem {
34673478 id : node_id,
34683479 name : i. ident . name ,
3469- attrs : self . lower_attrs ( & i. attrs ) ,
3480+ attrs : self . lower_attrs ( & i. attrs ) . into ( ) ,
34703481 node : match i. node {
34713482 ForeignItemKind :: Fn ( ref fdec, ref generics) => {
34723483 let ( generics, ( fn_dec, fn_args) ) = self . add_in_band_defs (
@@ -4025,7 +4036,7 @@ impl<'a> LoweringContext<'a> {
40254036 hir:: ExprKind :: Struct ( struct_path, fields, None )
40264037 } ,
40274038 span : e. span ,
4028- attrs : e. attrs . clone ( ) ,
4039+ attrs : self . lower_attrs ( & e. attrs ) . into ( ) ,
40294040 } ;
40304041 }
40314042 ExprKind :: Path ( ref qself, ref path) => {
@@ -4111,7 +4122,7 @@ impl<'a> LoweringContext<'a> {
41114122 ex. span = e. span ;
41124123 }
41134124 // merge attributes into the inner expression.
4114- let mut attrs = e. attrs . clone ( ) ;
4125+ let mut attrs: ThinVec < _ > = self . lower_attrs ( & e. attrs ) . into ( ) ;
41154126 attrs. extend :: < Vec < _ > > ( ex. attrs . into ( ) ) ;
41164127 ex. attrs = attrs;
41174128 return ex;
@@ -4394,7 +4405,8 @@ impl<'a> LoweringContext<'a> {
43944405 let result = P ( self . expr_ident ( e. span , result_ident, let_stmt_binding) ) ;
43954406 let block = P ( self . block_all ( e. span , hir_vec ! [ let_stmt] , Some ( result) ) ) ;
43964407 // add the attributes to the outer returned expr node
4397- return self . expr_block ( block, e. attrs . clone ( ) ) ;
4408+ let attrs = self . lower_attrs ( & e. attrs ) . into ( ) ;
4409+ return self . expr_block ( block, attrs) ;
43984410 }
43994411
44004412 // Desugar ExprKind::Try
@@ -4507,7 +4519,7 @@ impl<'a> LoweringContext<'a> {
45074519 hir_id,
45084520 node : kind,
45094521 span : e. span ,
4510- attrs : e. attrs . clone ( ) ,
4522+ attrs : self . lower_attrs ( & e. attrs ) . into ( ) ,
45114523 }
45124524 }
45134525
@@ -4685,7 +4697,7 @@ impl<'a> LoweringContext<'a> {
46854697 }
46864698 }
46874699
4688- fn expr_break ( & mut self , span : Span , attrs : ThinVec < Attribute > ) -> P < hir:: Expr > {
4700+ fn expr_break ( & mut self , span : Span , attrs : ThinVec < hir :: Attribute > ) -> P < hir:: Expr > {
46894701 let expr_break = hir:: ExprKind :: Break ( self . lower_loop_destination ( None ) , None ) ;
46904702 P ( self . expr ( span, expr_break, attrs) )
46914703 }
@@ -4708,7 +4720,7 @@ impl<'a> LoweringContext<'a> {
47084720 span : Span ,
47094721 ident : Ident ,
47104722 binding : NodeId ,
4711- attrs : ThinVec < Attribute > ,
4723+ attrs : ThinVec < hir :: Attribute > ,
47124724 ) -> hir:: Expr {
47134725 let expr_path = hir:: ExprKind :: Path ( hir:: QPath :: Resolved (
47144726 None ,
@@ -4731,7 +4743,7 @@ impl<'a> LoweringContext<'a> {
47314743 span : Span ,
47324744 components : & [ & str ] ,
47334745 params : Option < P < hir:: GenericArgs > > ,
4734- attrs : ThinVec < Attribute > ,
4746+ attrs : ThinVec < hir :: Attribute > ,
47354747 ) -> hir:: Expr {
47364748 let path = self . std_path ( span, components, params, true ) ;
47374749 self . expr (
@@ -4751,15 +4763,20 @@ impl<'a> LoweringContext<'a> {
47514763 self . expr ( span, hir:: ExprKind :: Match ( arg, arms, source) , ThinVec :: new ( ) )
47524764 }
47534765
4754- fn expr_block ( & mut self , b : P < hir:: Block > , attrs : ThinVec < Attribute > ) -> hir:: Expr {
4766+ fn expr_block ( & mut self , b : P < hir:: Block > , attrs : ThinVec < hir :: Attribute > ) -> hir:: Expr {
47554767 self . expr ( b. span , hir:: ExprKind :: Block ( b, None ) , attrs)
47564768 }
47574769
47584770 fn expr_tuple ( & mut self , sp : Span , exprs : hir:: HirVec < hir:: Expr > ) -> P < hir:: Expr > {
47594771 P ( self . expr ( sp, hir:: ExprKind :: Tup ( exprs) , ThinVec :: new ( ) ) )
47604772 }
47614773
4762- fn expr ( & mut self , span : Span , node : hir:: ExprKind , attrs : ThinVec < Attribute > ) -> hir:: Expr {
4774+ fn expr (
4775+ & mut self ,
4776+ span : Span ,
4777+ node : hir:: ExprKind ,
4778+ attrs : ThinVec < hir:: Attribute > ,
4779+ ) -> hir:: Expr {
47634780 let LoweredNodeId { node_id, hir_id } = self . next_id ( ) ;
47644781 hir:: Expr {
47654782 id : node_id,
0 commit comments