@@ -1106,6 +1106,19 @@ impl<'a> Resolver<'a> {
11061106 } ) ;
11071107 }
11081108
1109+ crate fn check_reserved_macro_name ( & mut self , ident : Ident , res : Res ) {
1110+ // Reserve some names that are not quite covered by the general check
1111+ // performed on `Resolver::builtin_attrs`.
1112+ if ident. name == sym:: cfg || ident. name == sym:: cfg_attr || ident. name == sym:: derive {
1113+ let macro_kind = self . opt_get_macro ( res) . map ( |ext| ext. macro_kind ( ) ) ;
1114+ if macro_kind. is_some ( ) && sub_namespace_match ( macro_kind, Some ( MacroKind :: Attr ) ) {
1115+ self . session . span_err (
1116+ ident. span , & format ! ( "name `{}` is reserved in attribute namespace" , ident)
1117+ ) ;
1118+ }
1119+ }
1120+ }
1121+
11091122 pub fn define_macro ( & mut self ,
11101123 item : & ast:: Item ,
11111124 expansion : Mark ,
@@ -1117,13 +1130,14 @@ impl<'a> Resolver<'a> {
11171130 let ext = Lrc :: new ( macro_rules:: compile ( & self . session . parse_sess ,
11181131 & self . session . features_untracked ( ) ,
11191132 item, self . session . edition ( ) ) ) ;
1133+ let macro_kind = ext. macro_kind ( ) ;
1134+ let res = Res :: Def ( DefKind :: Macro ( macro_kind) , def_id) ;
11201135 self . macro_map . insert ( def_id, ext) ;
11211136
11221137 let def = match item. node { ast:: ItemKind :: MacroDef ( ref def) => def, _ => unreachable ! ( ) } ;
11231138 if def. legacy {
11241139 let ident = ident. modern ( ) ;
11251140 self . macro_names . insert ( ident) ;
1126- let res = Res :: Def ( DefKind :: Macro ( MacroKind :: Bang ) , def_id) ;
11271141 let is_macro_export = attr:: contains_name ( & item. attrs , sym:: macro_export) ;
11281142 let vis = if is_macro_export {
11291143 ty:: Visibility :: Public
@@ -1142,14 +1156,11 @@ impl<'a> Resolver<'a> {
11421156 self . define ( module, ident, MacroNS ,
11431157 ( res, vis, item. span , expansion, IsMacroExport ) ) ;
11441158 } else {
1145- if !attr:: contains_name ( & item. attrs , sym:: rustc_builtin_macro) {
1146- self . check_reserved_macro_name ( ident, MacroNS ) ;
1147- }
1159+ self . check_reserved_macro_name ( ident, res) ;
11481160 self . unused_macros . insert ( def_id) ;
11491161 }
11501162 } else {
11511163 let module = self . current_module ;
1152- let res = Res :: Def ( DefKind :: Macro ( MacroKind :: Bang ) , def_id) ;
11531164 let vis = self . resolve_visibility ( & item. vis ) ;
11541165 if vis != ty:: Visibility :: Public {
11551166 self . unused_macros . insert ( def_id) ;
0 commit comments