@@ -78,7 +78,7 @@ use std::mem::replace;
78
78
use std:: rc:: Rc ;
79
79
80
80
use resolve_imports:: { ImportDirective , NameResolution } ;
81
- use macros:: { InvocationData , LegacyBinding } ;
81
+ use macros:: { InvocationData , LegacyBinding , LegacyScope } ;
82
82
83
83
// NB: This module needs to be declared first so diagnostics are
84
84
// registered before they are used.
@@ -1073,7 +1073,7 @@ pub struct Resolver<'a> {
1073
1073
1074
1074
privacy_errors : Vec < PrivacyError < ' a > > ,
1075
1075
ambiguity_errors : Vec < AmbiguityError < ' a > > ,
1076
- macro_shadowing_errors : FnvHashSet < Span > ,
1076
+ disallowed_shadowing : Vec < ( Name , Span , LegacyScope < ' a > ) > ,
1077
1077
1078
1078
arenas : & ' a ResolverArenas < ' a > ,
1079
1079
dummy_binding : & ' a NameBinding < ' a > ,
@@ -1260,7 +1260,7 @@ impl<'a> Resolver<'a> {
1260
1260
1261
1261
privacy_errors : Vec :: new ( ) ,
1262
1262
ambiguity_errors : Vec :: new ( ) ,
1263
- macro_shadowing_errors : FnvHashSet ( ) ,
1263
+ disallowed_shadowing : Vec :: new ( ) ,
1264
1264
1265
1265
arenas : arenas,
1266
1266
dummy_binding : arenas. alloc_name_binding ( NameBinding {
@@ -3353,7 +3353,8 @@ impl<'a> Resolver<'a> {
3353
3353
vis. is_accessible_from ( module. normal_ancestor_id . unwrap ( ) , self )
3354
3354
}
3355
3355
3356
- fn report_errors ( & self ) {
3356
+ fn report_errors ( & mut self ) {
3357
+ self . report_shadowing_errors ( ) ;
3357
3358
let mut reported_spans = FnvHashSet ( ) ;
3358
3359
3359
3360
for & AmbiguityError { span, name, b1, b2 } in & self . ambiguity_errors {
@@ -3381,6 +3382,20 @@ impl<'a> Resolver<'a> {
3381
3382
}
3382
3383
}
3383
3384
3385
+ fn report_shadowing_errors ( & mut self ) {
3386
+ let mut reported_errors = FnvHashSet ( ) ;
3387
+ for ( name, span, scope) in replace ( & mut self . disallowed_shadowing , Vec :: new ( ) ) {
3388
+ if self . resolve_macro_name ( scope, name, false ) . is_some ( ) &&
3389
+ reported_errors. insert ( ( name, span) ) {
3390
+ let msg = format ! ( "`{}` is already in scope" , name) ;
3391
+ self . session . struct_span_err ( span, & msg)
3392
+ . note ( "macro-expanded `macro_rules!`s and `#[macro_use]`s \
3393
+ may not shadow existing macros (see RFC 1560)")
3394
+ . emit ( ) ;
3395
+ }
3396
+ }
3397
+ }
3398
+
3384
3399
fn report_conflict ( & self ,
3385
3400
parent : Module ,
3386
3401
name : Name ,
0 commit comments