@@ -29,7 +29,7 @@ use syntax::attr;
2929
3030use syntax:: ast:: { self , Block , ForeignItem , ForeignItemKind , Item , ItemKind , NodeId } ;
3131use syntax:: ast:: { MetaItemKind , StmtKind , TraitItem , TraitItemKind , Variant } ;
32- use syntax:: ext:: base:: { MacroKind , SyntaxExtension } ;
32+ use syntax:: ext:: base:: SyntaxExtension ;
3333use syntax:: ext:: base:: Determinacy :: Undetermined ;
3434use syntax:: ext:: hygiene:: Mark ;
3535use syntax:: ext:: tt:: macro_rules;
@@ -46,6 +46,20 @@ use log::debug;
4646
4747type Res = def:: Res < NodeId > ;
4848
49+ fn proc_macro_stub ( item : & Item ) -> Option < ( Ident , Span ) > {
50+ if attr:: contains_name ( & item. attrs , sym:: proc_macro) ||
51+ attr:: contains_name ( & item. attrs , sym:: proc_macro_attribute) {
52+ return Some ( ( item. ident , item. span ) ) ;
53+ } else if let Some ( attr) = attr:: find_by_name ( & item. attrs , sym:: proc_macro_derive) {
54+ if let Some ( nested_meta) = attr. meta_item_list ( ) . and_then ( |list| list. get ( 0 ) . cloned ( ) ) {
55+ if let Some ( ident) = nested_meta. ident ( ) {
56+ return Some ( ( ident, ident. span ) ) ;
57+ }
58+ }
59+ }
60+ None
61+ }
62+
4963impl < ' a > ToNameBinding < ' a > for ( Module < ' a > , ty:: Visibility , Span , Mark ) {
5064 fn to_name_binding ( self , arenas : & ' a ResolverArenas < ' a > ) -> & ' a NameBinding < ' a > {
5165 arenas. alloc_name_binding ( NameBinding {
@@ -456,22 +470,8 @@ impl<'a> Resolver<'a> {
456470
457471 // Functions introducing procedural macros reserve a slot
458472 // in the macro namespace as well (see #52225).
459- if attr:: contains_name ( & item. attrs , sym:: proc_macro) ||
460- attr:: contains_name ( & item. attrs , sym:: proc_macro_attribute) {
461- let res = Res :: Def ( DefKind :: Macro ( MacroKind :: ProcMacroStub ) , res. def_id ( ) ) ;
462- self . define ( parent, ident, MacroNS , ( res, vis, sp, expansion) ) ;
463- }
464- if let Some ( attr) = attr:: find_by_name ( & item. attrs , sym:: proc_macro_derive) {
465- if let Some ( trait_attr) =
466- attr. meta_item_list ( ) . and_then ( |list| list. get ( 0 ) . cloned ( ) ) {
467- if let Some ( ident) = trait_attr. ident ( ) {
468- let res = Res :: Def (
469- DefKind :: Macro ( MacroKind :: ProcMacroStub ) ,
470- res. def_id ( ) ,
471- ) ;
472- self . define ( parent, ident, MacroNS , ( res, vis, ident. span , expansion) ) ;
473- }
474- }
473+ if let Some ( ( ident, span) ) = proc_macro_stub ( item) {
474+ self . define ( parent, ident, MacroNS , ( res, vis, span, expansion) ) ;
475475 }
476476 }
477477
@@ -778,8 +778,6 @@ impl<'a> Resolver<'a> {
778778
779779 crate fn opt_get_macro ( & mut self , res : Res ) -> Option < Lrc < SyntaxExtension > > {
780780 let def_id = match res {
781- Res :: Def ( DefKind :: Macro ( MacroKind :: ProcMacroStub ) , _) =>
782- return Some ( self . non_macro_attr ( true ) ) , // some dummy extension
783781 Res :: Def ( DefKind :: Macro ( ..) , def_id) => def_id,
784782 Res :: NonMacroAttr ( attr_kind) =>
785783 return Some ( self . non_macro_attr ( attr_kind == NonMacroAttrKind :: Tool ) ) ,
0 commit comments