@@ -1100,6 +1100,7 @@ impl<'a> fmt::Debug for ModuleData<'a> {
11001100pub struct NameBinding < ' a > {
11011101 kind : NameBindingKind < ' a > ,
11021102 expansion : Mark ,
1103+ is_macro_export : bool ,
11031104 span : Span ,
11041105 vis : ty:: Visibility ,
11051106}
@@ -1141,12 +1142,20 @@ struct UseError<'a> {
11411142 better : bool ,
11421143}
11431144
1145+ #[ derive( Clone , Copy , Debug ) ]
1146+ enum AmbiguityErrorKind {
1147+ RecordUse ,
1148+ ResolveLexical ,
1149+ ResolveInModule ,
1150+ }
1151+
11441152struct AmbiguityError < ' a > {
11451153 span : Span ,
11461154 name : Name ,
11471155 lexical : bool ,
11481156 b1 : & ' a NameBinding < ' a > ,
11491157 b2 : & ' a NameBinding < ' a > ,
1158+ kind : AmbiguityErrorKind ,
11501159}
11511160
11521161impl < ' a > NameBinding < ' a > {
@@ -1393,7 +1402,6 @@ pub struct Resolver<'a> {
13931402 macro_map : FxHashMap < DefId , Lrc < SyntaxExtension > > ,
13941403 macro_defs : FxHashMap < Mark , DefId > ,
13951404 local_macro_def_scopes : FxHashMap < NodeId , Module < ' a > > ,
1396- macro_exports : Vec < Export > ,
13971405 pub whitelisted_legacy_custom_derives : Vec < Name > ,
13981406 pub found_unresolved_macro : bool ,
13991407
@@ -1426,6 +1434,9 @@ pub struct Resolver<'a> {
14261434
14271435 /// Only supposed to be used by rustdoc, otherwise should be false.
14281436 pub ignore_extern_prelude_feature : bool ,
1437+
1438+ /// Macro invocations in the whole crate that can expand into a `#[macro_export] macro_rules`.
1439+ unresolved_invocations_macro_export : FxHashSet < Mark > ,
14291440}
14301441
14311442/// Nothing really interesting here, it just provides memory for the rest of the crate.
@@ -1703,6 +1714,7 @@ impl<'a> Resolver<'a> {
17031714 expansion : Mark :: root ( ) ,
17041715 span : DUMMY_SP ,
17051716 vis : ty:: Visibility :: Public ,
1717+ is_macro_export : false ,
17061718 } ) ,
17071719
17081720 crate_loader,
@@ -1711,7 +1723,6 @@ impl<'a> Resolver<'a> {
17111723 all_macros : FxHashMap ( ) ,
17121724 lexical_macro_resolutions : Vec :: new ( ) ,
17131725 macro_map : FxHashMap ( ) ,
1714- macro_exports : Vec :: new ( ) ,
17151726 invocations,
17161727 macro_defs,
17171728 local_macro_def_scopes : FxHashMap ( ) ,
@@ -1726,6 +1737,7 @@ impl<'a> Resolver<'a> {
17261737 current_type_ascription : Vec :: new ( ) ,
17271738 injected_crate : None ,
17281739 ignore_extern_prelude_feature : false ,
1740+ unresolved_invocations_macro_export : FxHashSet ( ) ,
17291741 }
17301742 }
17311743
@@ -1797,6 +1809,7 @@ impl<'a> Resolver<'a> {
17971809 NameBindingKind :: Ambiguity { b1, b2 } => {
17981810 self . ambiguity_errors . push ( AmbiguityError {
17991811 span, name : ident. name , lexical : false , b1, b2,
1812+ kind : AmbiguityErrorKind :: RecordUse
18001813 } ) ;
18011814 true
18021815 }
@@ -1957,7 +1970,6 @@ impl<'a> Resolver<'a> {
19571970 module : Module < ' a > ,
19581971 mut ident : Ident ,
19591972 ns : Namespace ,
1960- ignore_unresolved_invocations : bool ,
19611973 record_used : bool ,
19621974 span : Span )
19631975 -> Result < & ' a NameBinding < ' a > , Determinacy > {
@@ -1967,7 +1979,7 @@ impl<'a> Resolver<'a> {
19671979 self . current_module = self . macro_def_scope ( def) ;
19681980 }
19691981 let result = self . resolve_ident_in_module_unadjusted (
1970- module, ident, ns, ignore_unresolved_invocations , record_used, span,
1982+ module, ident, ns, false , record_used, span,
19711983 ) ;
19721984 self . current_module = orig_current_module;
19731985 result
@@ -2460,7 +2472,7 @@ impl<'a> Resolver<'a> {
24602472 // If there is a TraitRef in scope for an impl, then the method must be in the
24612473 // trait.
24622474 if let Some ( ( module, _) ) = self . current_trait_ref {
2463- if self . resolve_ident_in_module ( module, ident, ns, false , false , span) . is_err ( ) {
2475+ if self . resolve_ident_in_module ( module, ident, ns, false , span) . is_err ( ) {
24642476 let path = & self . current_trait_ref . as_ref ( ) . unwrap ( ) . 1 . path ;
24652477 resolve_error ( self , span, err ( ident. name , & path_names_to_string ( path) ) ) ;
24662478 }
@@ -3410,7 +3422,7 @@ impl<'a> Resolver<'a> {
34103422 }
34113423
34123424 let binding = if let Some ( module) = module {
3413- self . resolve_ident_in_module ( module, ident, ns, false , record_used, path_span)
3425+ self . resolve_ident_in_module ( module, ident, ns, record_used, path_span)
34143426 } else if opt_ns == Some ( MacroNS ) {
34153427 self . resolve_lexical_macro_path_segment ( ident, ns, record_used, path_span)
34163428 . map ( MacroBinding :: binding)
@@ -3704,7 +3716,7 @@ impl<'a> Resolver<'a> {
37043716 // Look for associated items in the current trait.
37053717 if let Some ( ( module, _) ) = self . current_trait_ref {
37063718 if let Ok ( binding) =
3707- self . resolve_ident_in_module ( module, ident, ns, false , false , module. span ) {
3719+ self . resolve_ident_in_module ( module, ident, ns, false , module. span ) {
37083720 let def = binding. def ( ) ;
37093721 if filter_fn ( def) {
37103722 return Some ( if self . has_self . contains ( & def. def_id ( ) ) {
@@ -4017,7 +4029,7 @@ impl<'a> Resolver<'a> {
40174029 let mut found_traits = Vec :: new ( ) ;
40184030 // Look for the current trait.
40194031 if let Some ( ( module, _) ) = self . current_trait_ref {
4020- if self . resolve_ident_in_module ( module, ident, ns, false , false , module. span ) . is_ok ( ) {
4032+ if self . resolve_ident_in_module ( module, ident, ns, false , module. span ) . is_ok ( ) {
40214033 let def_id = module. def_id ( ) . unwrap ( ) ;
40224034 found_traits. push ( TraitCandidate { def_id : def_id, import_id : None } ) ;
40234035 }
@@ -4290,7 +4302,7 @@ impl<'a> Resolver<'a> {
42904302 self . report_proc_macro_import ( krate) ;
42914303 let mut reported_spans = FxHashSet ( ) ;
42924304
4293- for & AmbiguityError { span, name, b1, b2, lexical } in & self . ambiguity_errors {
4305+ for & AmbiguityError { span, name, b1, b2, lexical, kind } in & self . ambiguity_errors {
42944306 if !reported_spans. insert ( span) { continue }
42954307 let participle = |binding : & NameBinding | {
42964308 if binding. is_import ( ) { "imported" } else { "defined" }
@@ -4307,7 +4319,8 @@ impl<'a> Resolver<'a> {
43074319 if b1. is_import( ) { "imports" } else { "items" } )
43084320 } ;
43094321
4310- let mut err = struct_span_err ! ( self . session, span, E0659 , "`{}` is ambiguous" , name) ;
4322+ let mut err = struct_span_err ! ( self . session, span, E0659 ,
4323+ "`{}` is ambiguous {:?}" , name, kind) ;
43114324 err. span_note ( b1. span , & msg1) ;
43124325 match b2. def ( ) {
43134326 Def :: Macro ( ..) if b2. span . is_dummy ( ) =>
0 commit comments