@@ -220,23 +220,6 @@ impl<'a, 'crateloader: 'a> base::Resolver for Resolver<'a, 'crateloader> {
220220 }
221221 }
222222
223- fn add_unshadowable_attr ( & mut self , ident : ast:: Ident , ext : Lrc < SyntaxExtension > ) {
224- let def_id = DefId {
225- krate : BUILTIN_MACROS_CRATE ,
226- index : DefIndex :: from_array_index ( self . macro_map . len ( ) ,
227- DefIndexAddressSpace :: Low ) ,
228- } ;
229- let kind = ext. kind ( ) ;
230- self . macro_map . insert ( def_id, ext) ;
231- let binding = self . arenas . alloc_name_binding ( NameBinding {
232- kind : NameBindingKind :: Def ( Def :: Macro ( def_id, kind) , false ) ,
233- span : DUMMY_SP ,
234- vis : ty:: Visibility :: Invisible ,
235- expansion : Mark :: root ( ) ,
236- } ) ;
237- self . unshadowable_attrs . insert ( ident. name , binding) ;
238- }
239-
240223 fn resolve_imports ( & mut self ) {
241224 ImportResolver { resolver : self } . resolve_imports ( )
242225 }
@@ -493,14 +476,8 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
493476 return def;
494477 }
495478
496- if kind == MacroKind :: Attr {
497- if let Some ( ext) = self . unshadowable_attrs . get ( & path[ 0 ] . name ) {
498- return Ok ( ext. def ( ) ) ;
499- }
500- }
501-
502479 let legacy_resolution = self . resolve_legacy_scope (
503- path[ 0 ] , invoc_id, invocation. parent_legacy_scope . get ( ) , false
480+ path[ 0 ] , invoc_id, invocation. parent_legacy_scope . get ( ) , false , kind == MacroKind :: Attr
504481 ) ;
505482 let result = if let Some ( legacy_binding) = legacy_resolution {
506483 Ok ( legacy_binding. def ( ) )
@@ -643,7 +620,19 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
643620 }
644621 WhereToResolve :: MacroUsePrelude => {
645622 match self . macro_use_prelude . get ( & ident. name ) . cloned ( ) {
646- Some ( binding) => Ok ( ( binding, FromPrelude ( true ) ) ) ,
623+ Some ( binding) => {
624+ let mut result = Ok ( ( binding, FromPrelude ( true ) ) ) ;
625+ // FIXME: Keep some built-in macros working even if they are
626+ // shadowed by non-attribute macros imported with `macro_use`.
627+ // We need to come up with some more principled approach instead.
628+ if is_attr && ( ident. name == "test" || ident. name == "bench" ) {
629+ if let Def :: Macro ( _, MacroKind :: Bang ) =
630+ binding. def_ignoring_ambiguity ( ) {
631+ result = Err ( Determinacy :: Determined ) ;
632+ }
633+ }
634+ result
635+ }
647636 None => Err ( Determinacy :: Determined ) ,
648637 }
649638 }
@@ -811,8 +800,16 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
811800 ident : Ident ,
812801 invoc_id : Mark ,
813802 invoc_parent_legacy_scope : LegacyScope < ' a > ,
814- record_used : bool )
803+ record_used : bool ,
804+ is_attr : bool )
815805 -> Option < & ' a NameBinding < ' a > > {
806+ if is_attr && ( ident. name == "test" || ident. name == "bench" ) {
807+ // FIXME: Keep some built-in macros working even if they are
808+ // shadowed by user-defined `macro_rules`.
809+ // We need to come up with some more principled approach instead.
810+ return None ;
811+ }
812+
816813 let ident = ident. modern ( ) ;
817814
818815 // This is *the* result, resolution from the scope closest to the resolved identifier.
@@ -898,7 +895,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
898895 let span = ident. span ;
899896 let invocation = self . invocations [ & invoc_id] ;
900897 let legacy_resolution = self . resolve_legacy_scope (
901- ident, invoc_id, invocation. parent_legacy_scope . get ( ) , true
898+ ident, invoc_id, invocation. parent_legacy_scope . get ( ) , true , kind == MacroKind :: Attr
902899 ) ;
903900 let resolution = self . resolve_lexical_macro_path_segment (
904901 ident, MacroNS , invoc_id, true , true , kind == MacroKind :: Attr , span
0 commit comments