@@ -220,23 +220,6 @@ impl<'a, 'crateloader: 'a> base::Resolver for Resolver<'a, 'crateloader> {
220
220
}
221
221
}
222
222
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
-
240
223
fn resolve_imports ( & mut self ) {
241
224
ImportResolver { resolver : self } . resolve_imports ( )
242
225
}
@@ -493,14 +476,8 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
493
476
return def;
494
477
}
495
478
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
-
502
479
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
504
481
) ;
505
482
let result = if let Some ( legacy_binding) = legacy_resolution {
506
483
Ok ( legacy_binding. def ( ) )
@@ -643,7 +620,19 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
643
620
}
644
621
WhereToResolve :: MacroUsePrelude => {
645
622
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
+ }
647
636
None => Err ( Determinacy :: Determined ) ,
648
637
}
649
638
}
@@ -811,8 +800,16 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
811
800
ident : Ident ,
812
801
invoc_id : Mark ,
813
802
invoc_parent_legacy_scope : LegacyScope < ' a > ,
814
- record_used : bool )
803
+ record_used : bool ,
804
+ is_attr : bool )
815
805
-> 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
+
816
813
let ident = ident. modern ( ) ;
817
814
818
815
// This is *the* result, resolution from the scope closest to the resolved identifier.
@@ -898,7 +895,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
898
895
let span = ident. span ;
899
896
let invocation = self . invocations [ & invoc_id] ;
900
897
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
902
899
) ;
903
900
let resolution = self . resolve_lexical_macro_path_segment (
904
901
ident, MacroNS , invoc_id, true , true , kind == MacroKind :: Attr , span
0 commit comments