@@ -34,7 +34,7 @@ use syntax::attr;
3434
3535use syntax:: ast:: { self , Block , ForeignItem , ForeignItemKind , Item , ItemKind , NodeId } ;
3636use syntax:: ast:: { Mutability , StmtKind , TraitItem , TraitItemKind , Variant } ;
37- use syntax:: ext:: base:: SyntaxExtension ;
37+ use syntax:: ext:: base:: { MacroKind , SyntaxExtension } ;
3838use syntax:: ext:: base:: Determinacy :: Undetermined ;
3939use syntax:: ext:: hygiene:: Mark ;
4040use syntax:: ext:: tt:: macro_rules;
@@ -335,6 +335,24 @@ impl<'a> Resolver<'a> {
335335 ItemKind :: Fn ( ..) => {
336336 let def = Def :: Fn ( self . definitions . local_def_id ( item. id ) ) ;
337337 self . define ( parent, ident, ValueNS , ( def, vis, sp, expansion) ) ;
338+
339+ // Functions introducing procedural macros reserve a slot
340+ // in the macro namespace as well (see #52225).
341+ if attr:: contains_name ( & item. attrs , "proc_macro" ) ||
342+ attr:: contains_name ( & item. attrs , "proc_macro_attribute" ) {
343+ let def = Def :: Macro ( def. def_id ( ) , MacroKind :: ProcMacroStub ) ;
344+ self . define ( parent, ident, MacroNS , ( def, vis, sp, expansion) ) ;
345+ }
346+ if let Some ( attr) = attr:: find_by_name ( & item. attrs , "proc_macro_derive" ) {
347+ if let Some ( trait_attr) =
348+ attr. meta_item_list ( ) . and_then ( |list| list. get ( 0 ) . cloned ( ) ) {
349+ if let Some ( ident) = trait_attr. name ( ) . map ( Ident :: with_empty_ctxt) {
350+ let sp = trait_attr. span ;
351+ let def = Def :: Macro ( def. def_id ( ) , MacroKind :: ProcMacroStub ) ;
352+ self . define ( parent, ident, MacroNS , ( def, vis, sp, expansion) ) ;
353+ }
354+ }
355+ }
338356 }
339357
340358 // These items live in the type namespace.
0 commit comments