@@ -148,21 +148,57 @@ impl<'hir> LoweringContext<'_, 'hir> {
148148 }
149149 }
150150
151+ fn generate_extra_attrs_for_item_kind (
152+ & mut self ,
153+ id : NodeId ,
154+ i : & ItemKind ,
155+ ) -> Vec < hir:: Attribute > {
156+ match i {
157+ ItemKind :: Fn ( box Fn { eii_impl, .. } ) => {
158+ let mut res = Vec :: new ( ) ;
159+
160+ for ( id, path) in eii_impl {
161+ let did = self . lower_path_simple_eii ( * id, path) ;
162+ res. push ( hir:: Attribute :: Parsed ( AttributeKind :: EiiImpl { eii_macro : did } ) ) ;
163+ }
164+
165+ res
166+ }
167+ ItemKind :: MacroDef ( _, MacroDef { eii_macro_for : Some ( path) , .. } ) => {
168+ vec ! [ hir:: Attribute :: Parsed ( AttributeKind :: EiiMacroFor {
169+ eii_extern_item: self . lower_path_simple_eii( id, path) ,
170+ } ) ]
171+ }
172+ ItemKind :: ExternCrate ( ..)
173+ | ItemKind :: Use ( ..)
174+ | ItemKind :: Static ( ..)
175+ | ItemKind :: Const ( ..)
176+ | ItemKind :: Mod ( ..)
177+ | ItemKind :: ForeignMod ( ..)
178+ | ItemKind :: GlobalAsm ( ..)
179+ | ItemKind :: TyAlias ( ..)
180+ | ItemKind :: Enum ( ..)
181+ | ItemKind :: Struct ( ..)
182+ | ItemKind :: Union ( ..)
183+ | ItemKind :: Trait ( ..)
184+ | ItemKind :: TraitAlias ( ..)
185+ | ItemKind :: Impl ( ..)
186+ | ItemKind :: MacCall ( ..)
187+ | ItemKind :: MacroDef ( ..)
188+ | ItemKind :: Delegation ( ..)
189+ | ItemKind :: DelegationMac ( ..) => Vec :: new ( ) ,
190+ }
191+ }
192+
151193 fn lower_item ( & mut self , i : & Item ) -> & ' hir hir:: Item < ' hir > {
152194 let vis_span = self . lower_span ( i. vis . span ) ;
153195 let hir_id = hir:: HirId :: make_owner ( self . current_hir_id_owner . def_id ) ;
154196
155- let mut extra_hir_attributes = Vec :: new ( ) ;
156- if let ItemKind :: Fn ( f) = & i. kind {
157- extra_hir_attributes. extend ( f. eii_impl . iter ( ) . map ( |( id, mi) | {
158- let did = self . lower_path_simple_eii ( * id, & mi. path ) ;
159-
160- hir:: Attribute :: Parsed ( AttributeKind :: EiiImpl { eii_macro : did } )
161- } ) ) ;
162- }
197+ let extra_hir_attributes = self . generate_extra_attrs_for_item_kind ( i. id , & i. kind ) ;
163198
164199 let attrs = self . lower_attrs ( hir_id, & i. attrs , i. span , & extra_hir_attributes) ;
165200 let kind = self . lower_item_kind ( i. span , i. id , hir_id, attrs, vis_span, & i. kind ) ;
201+
166202 let item = hir:: Item {
167203 owner_id : hir_id. expect_owner ( ) ,
168204 kind,
@@ -233,7 +269,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
233269 body,
234270 contract,
235271 define_opaque,
236- eii_impl,
237272 ..
238273 } ) => {
239274 self . with_new_scopes ( * fn_sig_span, |this| {
@@ -475,7 +510,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
475510 ) ;
476511 hir:: ItemKind :: TraitAlias ( ident, generics, bounds)
477512 }
478- ItemKind :: MacroDef ( ident, MacroDef { body, macro_rules, eii_macro_for } ) => {
513+ ItemKind :: MacroDef ( ident, MacroDef { body, macro_rules, eii_macro_for : _ } ) => {
479514 let ident = self . lower_ident ( * ident) ;
480515 let body = P ( self . lower_delim_args ( body) ) ;
481516 let def_id = self . local_def_id ( id) ;
@@ -493,14 +528,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
493528 eii_macro_for : None ,
494529 } ) ;
495530
496- hir:: ItemKind :: Macro {
497- name : ident,
498- ast_macro_def,
499- kind : macro_kind,
500- eii_macro_for : eii_macro_for
501- . as_ref ( )
502- . map ( |path| self . lower_path_simple_eii ( id, path) ) ,
503- }
531+ hir:: ItemKind :: Macro ( ident, ast_macro_def, macro_kind)
504532 }
505533 ItemKind :: Delegation ( box delegation) => {
506534 let delegation_results = self . lower_delegation ( delegation, id, false ) ;
@@ -680,6 +708,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
680708 self . lower_generics ( generics, i. id , itctx, |this| {
681709 (
682710 // Disallow `impl Trait` in foreign items.
711+ this. lower_fn_decl ( fdec, i. id , sig. span , FnDeclKind :: ExternFn , None ) ,
683712 this. lower_fn_params_to_idents ( fdec) ,
684713 )
685714 } ) ;
0 commit comments