@@ -80,7 +80,7 @@ use std::mem::replace;
80
80
use rustc_data_structures:: sync:: Lrc ;
81
81
82
82
use resolve_imports:: { ImportDirective , ImportDirectiveSubclass , NameResolution , ImportResolver } ;
83
- use macros:: { InvocationData , LegacyBinding , MacroBinding } ;
83
+ use macros:: { InvocationData , LegacyBinding } ;
84
84
85
85
// NB: This module needs to be declared first so diagnostics are
86
86
// registered before they are used.
@@ -1399,7 +1399,7 @@ pub struct Resolver<'a, 'b: 'a> {
1399
1399
proc_mac_errors : Vec < macros:: ProcMacError > ,
1400
1400
/// crate-local macro expanded `macro_export` referred to by a module-relative path
1401
1401
macro_expanded_macro_export_errors : BTreeSet < ( Span , Span ) > ,
1402
-
1402
+ /// macro-expanded `macro_rules` shadowing existing macros
1403
1403
disallowed_shadowing : Vec < & ' a LegacyBinding < ' a > > ,
1404
1404
1405
1405
arenas : & ' a ResolverArenas < ' a > ,
@@ -3529,7 +3529,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
3529
3529
} else if opt_ns == Some ( MacroNS ) {
3530
3530
assert ! ( ns == TypeNS ) ;
3531
3531
self . resolve_lexical_macro_path_segment ( ident, ns, record_used, record_used,
3532
- false , path_span) . map ( MacroBinding :: binding )
3532
+ false , path_span) . map ( | ( b , _ ) | b )
3533
3533
} else {
3534
3534
let record_used_id =
3535
3535
if record_used { crate_lint. node_id ( ) . or ( Some ( CRATE_NODE_ID ) ) } else { None } ;
@@ -4431,6 +4431,42 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
4431
4431
vis. is_accessible_from ( module. normal_ancestor_id , self )
4432
4432
}
4433
4433
4434
+ fn report_ambiguity_error (
4435
+ & self , name : Name , span : Span , _lexical : bool ,
4436
+ def1 : Def , is_import1 : bool , is_glob1 : bool , from_expansion1 : bool , span1 : Span ,
4437
+ def2 : Def , is_import2 : bool , _is_glob2 : bool , _from_expansion2 : bool , span2 : Span ,
4438
+ ) {
4439
+ let participle = |is_import : bool | if is_import { "imported" } else { "defined" } ;
4440
+ let msg1 = format ! ( "`{}` could refer to the name {} here" , name, participle( is_import1) ) ;
4441
+ let msg2 =
4442
+ format ! ( "`{}` could also refer to the name {} here" , name, participle( is_import2) ) ;
4443
+ let note = if from_expansion1 {
4444
+ Some ( if let Def :: Macro ( ..) = def1 {
4445
+ format ! ( "macro-expanded {} do not shadow" ,
4446
+ if is_import1 { "macro imports" } else { "macros" } )
4447
+ } else {
4448
+ format ! ( "macro-expanded {} do not shadow when used in a macro invocation path" ,
4449
+ if is_import1 { "imports" } else { "items" } )
4450
+ } )
4451
+ } else if is_glob1 {
4452
+ Some ( format ! ( "consider adding an explicit import of `{}` to disambiguate" , name) )
4453
+ } else {
4454
+ None
4455
+ } ;
4456
+
4457
+ let mut err = struct_span_err ! ( self . session, span, E0659 , "`{}` is ambiguous" , name) ;
4458
+ err. span_note ( span1, & msg1) ;
4459
+ match def2 {
4460
+ Def :: Macro ( ..) if span2. is_dummy ( ) =>
4461
+ err. note ( & format ! ( "`{}` is also a builtin macro" , name) ) ,
4462
+ _ => err. span_note ( span2, & msg2) ,
4463
+ } ;
4464
+ if let Some ( note) = note {
4465
+ err. note ( & note) ;
4466
+ }
4467
+ err. emit ( ) ;
4468
+ }
4469
+
4434
4470
fn report_errors ( & mut self , krate : & Crate ) {
4435
4471
self . report_shadowing_errors ( ) ;
4436
4472
self . report_with_use_injections ( krate) ;
@@ -4446,30 +4482,15 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
4446
4482
}
4447
4483
4448
4484
for & AmbiguityError { span, name, b1, b2, lexical } in & self . ambiguity_errors {
4449
- if !reported_spans. insert ( span) { continue }
4450
- let participle = |binding : & NameBinding | {
4451
- if binding. is_import ( ) { "imported" } else { "defined" }
4452
- } ;
4453
- let msg1 = format ! ( "`{}` could refer to the name {} here" , name, participle( b1) ) ;
4454
- let msg2 = format ! ( "`{}` could also refer to the name {} here" , name, participle( b2) ) ;
4455
- let note = if b1. expansion == Mark :: root ( ) || !lexical && b1. is_glob_import ( ) {
4456
- format ! ( "consider adding an explicit import of `{}` to disambiguate" , name)
4457
- } else if let Def :: Macro ( ..) = b1. def ( ) {
4458
- format ! ( "macro-expanded {} do not shadow" ,
4459
- if b1. is_import( ) { "macro imports" } else { "macros" } )
4460
- } else {
4461
- format ! ( "macro-expanded {} do not shadow when used in a macro invocation path" ,
4462
- if b1. is_import( ) { "imports" } else { "items" } )
4463
- } ;
4464
-
4465
- let mut err = struct_span_err ! ( self . session, span, E0659 , "`{}` is ambiguous" , name) ;
4466
- err. span_note ( b1. span , & msg1) ;
4467
- match b2. def ( ) {
4468
- Def :: Macro ( ..) if b2. span . is_dummy ( ) =>
4469
- err. note ( & format ! ( "`{}` is also a builtin macro" , name) ) ,
4470
- _ => err. span_note ( b2. span , & msg2) ,
4471
- } ;
4472
- err. note ( & note) . emit ( ) ;
4485
+ if reported_spans. insert ( span) {
4486
+ self . report_ambiguity_error (
4487
+ name, span, lexical,
4488
+ b1. def ( ) , b1. is_import ( ) , b1. is_glob_import ( ) ,
4489
+ b1. expansion != Mark :: root ( ) , b1. span ,
4490
+ b2. def ( ) , b2. is_import ( ) , b2. is_glob_import ( ) ,
4491
+ b2. expansion != Mark :: root ( ) , b2. span ,
4492
+ ) ;
4493
+ }
4473
4494
}
4474
4495
4475
4496
for & PrivacyError ( span, name, binding) in & self . privacy_errors {
0 commit comments