@@ -217,42 +217,40 @@ impl<'hir> LoweringContext<'_, 'hir> {
217
217
pub fn lower_item ( & mut self , i : & Item ) -> Option < hir:: Item < ' hir > > {
218
218
let mut ident = i. ident ;
219
219
let mut vis = self . lower_visibility ( & i. vis , None ) ;
220
- let attrs = self . lower_attrs ( & i. attrs ) ;
221
220
222
221
if let ItemKind :: MacroDef ( MacroDef { ref body, macro_rules } ) = i. kind {
223
222
if !macro_rules || self . sess . contains_name ( & i. attrs , sym:: macro_export) {
224
- let def_id = self . lower_node_id ( i. id ) . expect_owner ( ) ;
223
+ let hir_id = self . lower_node_id ( i. id ) ;
224
+ let attrs = self . lower_attrs ( hir_id, & i. attrs ) ;
225
225
let body = P ( self . lower_mac_args ( body) ) ;
226
226
self . exported_macros . push ( hir:: MacroDef {
227
227
ident,
228
228
vis,
229
229
attrs,
230
- def_id,
230
+ def_id : hir_id . expect_owner ( ) ,
231
231
span : i. span ,
232
232
ast : MacroDef { body, macro_rules } ,
233
233
} ) ;
234
234
} else {
235
- self . non_exported_macro_attrs . extend ( attrs. iter ( ) . cloned ( ) ) ;
235
+ for a in i. attrs . iter ( ) {
236
+ let a = self . lower_attr ( a) ;
237
+ self . non_exported_macro_attrs . push ( a) ;
238
+ }
236
239
}
237
240
return None ;
238
241
}
239
242
240
- let kind = self . lower_item_kind ( i. span , i. id , & mut ident, attrs, & mut vis, & i. kind ) ;
241
-
242
- Some ( hir:: Item {
243
- def_id : self . lower_node_id ( i. id ) . expect_owner ( ) ,
244
- ident,
245
- attrs,
246
- kind,
247
- vis,
248
- span : i. span ,
249
- } )
243
+ let hir_id = self . lower_node_id ( i. id ) ;
244
+ let attrs = self . lower_attrs ( hir_id, & i. attrs ) ;
245
+ let kind = self . lower_item_kind ( i. span , i. id , hir_id, & mut ident, attrs, & mut vis, & i. kind ) ;
246
+ Some ( hir:: Item { def_id : hir_id. expect_owner ( ) , ident, attrs, kind, vis, span : i. span } )
250
247
}
251
248
252
249
fn lower_item_kind (
253
250
& mut self ,
254
251
span : Span ,
255
252
id : NodeId ,
253
+ hir_id : hir:: HirId ,
256
254
ident : & mut Ident ,
257
255
attrs : & ' hir [ Attribute ] ,
258
256
vis : & mut hir:: Visibility < ' hir > ,
@@ -365,14 +363,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
365
363
self . lower_generics ( generics, ImplTraitContext :: disallowed ( ) ) ,
366
364
) ,
367
365
ItemKind :: Struct ( ref struct_def, ref generics) => {
368
- let struct_def = self . lower_variant_data ( struct_def) ;
366
+ let struct_def = self . lower_variant_data ( hir_id , struct_def) ;
369
367
hir:: ItemKind :: Struct (
370
368
struct_def,
371
369
self . lower_generics ( generics, ImplTraitContext :: disallowed ( ) ) ,
372
370
)
373
371
}
374
372
ItemKind :: Union ( ref vdata, ref generics) => {
375
- let vdata = self . lower_variant_data ( vdata) ;
373
+ let vdata = self . lower_variant_data ( hir_id , vdata) ;
376
374
hir:: ItemKind :: Union (
377
375
vdata,
378
376
self . lower_generics ( generics, ImplTraitContext :: disallowed ( ) ) ,
@@ -554,6 +552,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
554
552
let path = this. lower_path_extra ( res, & path, ParamMode :: Explicit , None ) ;
555
553
let kind = hir:: ItemKind :: Use ( path, hir:: UseKind :: Single ) ;
556
554
let vis = this. rebuild_vis ( & vis) ;
555
+ this. attrs . push_sparse ( new_id, attrs) ;
557
556
558
557
this. insert_item ( hir:: Item {
559
558
def_id : new_id. expect_owner ( ) ,
@@ -626,6 +625,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
626
625
627
626
let kind =
628
627
this. lower_use_tree ( use_tree, & prefix, id, & mut vis, & mut ident, attrs) ;
628
+ this. attrs . push_sparse ( new_hir_id, attrs) ;
629
629
630
630
this. insert_item ( hir:: Item {
631
631
def_id : new_hir_id. expect_owner ( ) ,
@@ -699,11 +699,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
699
699
}
700
700
701
701
fn lower_foreign_item ( & mut self , i : & ForeignItem ) -> hir:: ForeignItem < ' hir > {
702
- let def_id = self . resolver . local_def_id ( i. id ) ;
702
+ let hir_id = self . lower_node_id ( i. id ) ;
703
+ let def_id = hir_id. expect_owner ( ) ;
703
704
hir:: ForeignItem {
704
705
def_id,
705
706
ident : i. ident ,
706
- attrs : self . lower_attrs ( & i. attrs ) ,
707
+ attrs : self . lower_attrs ( hir_id , & i. attrs ) ,
707
708
kind : match i. kind {
708
709
ForeignItemKind :: Fn ( box FnKind ( _, ref sig, ref generics, _) ) => {
709
710
let fdec = & sig. decl ;
@@ -748,29 +749,43 @@ impl<'hir> LoweringContext<'_, 'hir> {
748
749
}
749
750
750
751
fn lower_variant ( & mut self , v : & Variant ) -> hir:: Variant < ' hir > {
752
+ let id = self . lower_node_id ( v. id ) ;
751
753
hir:: Variant {
752
- attrs : self . lower_attrs ( & v. attrs ) ,
753
- data : self . lower_variant_data ( & v. data ) ,
754
+ id,
755
+ attrs : self . lower_attrs ( id, & v. attrs ) ,
756
+ data : self . lower_variant_data ( id, & v. data ) ,
754
757
disr_expr : v. disr_expr . as_ref ( ) . map ( |e| self . lower_anon_const ( e) ) ,
755
- id : self . lower_node_id ( v. id ) ,
756
758
ident : v. ident ,
757
759
span : v. span ,
758
760
}
759
761
}
760
762
761
- fn lower_variant_data ( & mut self , vdata : & VariantData ) -> hir:: VariantData < ' hir > {
763
+ fn lower_variant_data (
764
+ & mut self ,
765
+ parent_id : hir:: HirId ,
766
+ vdata : & VariantData ,
767
+ ) -> hir:: VariantData < ' hir > {
762
768
match * vdata {
763
769
VariantData :: Struct ( ref fields, recovered) => hir:: VariantData :: Struct (
764
770
self . arena
765
771
. alloc_from_iter ( fields. iter ( ) . enumerate ( ) . map ( |f| self . lower_struct_field ( f) ) ) ,
766
772
recovered,
767
773
) ,
768
- VariantData :: Tuple ( ref fields, id) => hir:: VariantData :: Tuple (
769
- self . arena
770
- . alloc_from_iter ( fields. iter ( ) . enumerate ( ) . map ( |f| self . lower_struct_field ( f) ) ) ,
771
- self . lower_node_id ( id) ,
772
- ) ,
773
- VariantData :: Unit ( id) => hir:: VariantData :: Unit ( self . lower_node_id ( id) ) ,
774
+ VariantData :: Tuple ( ref fields, id) => {
775
+ let ctor_id = self . lower_node_id ( id) ;
776
+ self . attrs . push_sparse ( ctor_id, self . attrs [ parent_id] ) ;
777
+ hir:: VariantData :: Tuple (
778
+ self . arena . alloc_from_iter (
779
+ fields. iter ( ) . enumerate ( ) . map ( |f| self . lower_struct_field ( f) ) ,
780
+ ) ,
781
+ ctor_id,
782
+ )
783
+ }
784
+ VariantData :: Unit ( id) => {
785
+ let ctor_id = self . lower_node_id ( id) ;
786
+ self . attrs . push_sparse ( ctor_id, self . attrs [ parent_id] ) ;
787
+ hir:: VariantData :: Unit ( ctor_id)
788
+ }
774
789
}
775
790
}
776
791
@@ -787,22 +802,24 @@ impl<'hir> LoweringContext<'_, 'hir> {
787
802
} else {
788
803
self . lower_ty ( & f. ty , ImplTraitContext :: disallowed ( ) )
789
804
} ;
805
+ let hir_id = self . lower_node_id ( f. id ) ;
790
806
hir:: StructField {
791
807
span : f. span ,
792
- hir_id : self . lower_node_id ( f . id ) ,
808
+ hir_id,
793
809
ident : match f. ident {
794
810
Some ( ident) => ident,
795
811
// FIXME(jseyfried): positional field hygiene.
796
812
None => Ident :: new ( sym:: integer ( index) , f. span ) ,
797
813
} ,
798
814
vis : self . lower_visibility ( & f. vis , None ) ,
799
815
ty,
800
- attrs : self . lower_attrs ( & f. attrs ) ,
816
+ attrs : self . lower_attrs ( hir_id , & f. attrs ) ,
801
817
}
802
818
}
803
819
804
820
fn lower_trait_item ( & mut self , i : & AssocItem ) -> hir:: TraitItem < ' hir > {
805
- let trait_item_def_id = self . resolver . local_def_id ( i. id ) ;
821
+ let hir_id = self . lower_node_id ( i. id ) ;
822
+ let trait_item_def_id = hir_id. expect_owner ( ) ;
806
823
807
824
let ( generics, kind) = match i. kind {
808
825
AssocItemKind :: Const ( _, ref ty, ref default) => {
@@ -838,7 +855,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
838
855
hir:: TraitItem {
839
856
def_id : trait_item_def_id,
840
857
ident : i. ident ,
841
- attrs : self . lower_attrs ( & i. attrs ) ,
858
+ attrs : self . lower_attrs ( hir_id , & i. attrs ) ,
842
859
generics,
843
860
kind,
844
861
span : i. span ,
@@ -920,10 +937,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
920
937
// Since `default impl` is not yet implemented, this is always true in impls.
921
938
let has_value = true ;
922
939
let ( defaultness, _) = self . lower_defaultness ( i. kind . defaultness ( ) , has_value) ;
940
+ let hir_id = self . lower_node_id ( i. id ) ;
923
941
hir:: ImplItem {
924
- def_id : self . lower_node_id ( i . id ) . expect_owner ( ) ,
942
+ def_id : hir_id . expect_owner ( ) ,
925
943
ident : i. ident ,
926
- attrs : self . lower_attrs ( & i. attrs ) ,
944
+ attrs : self . lower_attrs ( hir_id , & i. attrs ) ,
927
945
generics,
928
946
vis : self . lower_visibility ( & i. vis , None ) ,
929
947
defaultness,
@@ -1024,9 +1042,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
1024
1042
}
1025
1043
1026
1044
fn lower_param ( & mut self , param : & Param ) -> hir:: Param < ' hir > {
1045
+ let hir_id = self . lower_node_id ( param. id ) ;
1027
1046
hir:: Param {
1028
- attrs : self . lower_attrs ( & param . attrs ) ,
1029
- hir_id : self . lower_node_id ( param. id ) ,
1047
+ hir_id ,
1048
+ attrs : self . lower_attrs ( hir_id , & param. attrs ) ,
1030
1049
pat : self . lower_pat ( & param. pat ) ,
1031
1050
ty_span : param. ty . span ,
1032
1051
span : param. span ,
0 commit comments