@@ -80,7 +80,7 @@ use std::mem::replace;
8080use rustc_data_structures:: sync:: Lrc ;
8181
8282use resolve_imports:: { ImportDirective , ImportDirectiveSubclass , NameResolution , ImportResolver } ;
83- use macros:: { InvocationData , LegacyBinding , MacroBinding } ;
83+ use macros:: { InvocationData , LegacyBinding } ;
8484
8585// NB: This module needs to be declared first so diagnostics are
8686// registered before they are used.
@@ -1399,7 +1399,7 @@ pub struct Resolver<'a, 'b: 'a> {
13991399 proc_mac_errors : Vec < macros:: ProcMacError > ,
14001400 /// crate-local macro expanded `macro_export` referred to by a module-relative path
14011401 macro_expanded_macro_export_errors : BTreeSet < ( Span , Span ) > ,
1402-
1402+ /// macro-expanded `macro_rules` shadowing existing macros
14031403 disallowed_shadowing : Vec < & ' a LegacyBinding < ' a > > ,
14041404
14051405 arenas : & ' a ResolverArenas < ' a > ,
@@ -3529,7 +3529,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
35293529 } else if opt_ns == Some ( MacroNS ) {
35303530 assert ! ( ns == TypeNS ) ;
35313531 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 )
35333533 } else {
35343534 let record_used_id =
35353535 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> {
44314431 vis. is_accessible_from ( module. normal_ancestor_id , self )
44324432 }
44334433
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+
44344470 fn report_errors ( & mut self , krate : & Crate ) {
44354471 self . report_shadowing_errors ( ) ;
44364472 self . report_with_use_injections ( krate) ;
@@ -4446,30 +4482,15 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
44464482 }
44474483
44484484 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+ }
44734494 }
44744495
44754496 for & PrivacyError ( span, name, binding) in & self . privacy_errors {
0 commit comments