@@ -1100,6 +1100,7 @@ impl<'a> fmt::Debug for ModuleData<'a> {
1100
1100
pub struct NameBinding < ' a > {
1101
1101
kind : NameBindingKind < ' a > ,
1102
1102
expansion : Mark ,
1103
+ is_macro_export : bool ,
1103
1104
span : Span ,
1104
1105
vis : ty:: Visibility ,
1105
1106
}
@@ -1141,12 +1142,20 @@ struct UseError<'a> {
1141
1142
better : bool ,
1142
1143
}
1143
1144
1145
+ #[ derive( Clone , Copy , Debug ) ]
1146
+ enum AmbiguityErrorKind {
1147
+ RecordUse ,
1148
+ ResolveLexical ,
1149
+ ResolveInModule ,
1150
+ }
1151
+
1144
1152
struct AmbiguityError < ' a > {
1145
1153
span : Span ,
1146
1154
name : Name ,
1147
1155
lexical : bool ,
1148
1156
b1 : & ' a NameBinding < ' a > ,
1149
1157
b2 : & ' a NameBinding < ' a > ,
1158
+ kind : AmbiguityErrorKind ,
1150
1159
}
1151
1160
1152
1161
impl < ' a > NameBinding < ' a > {
@@ -1380,13 +1389,10 @@ pub struct Resolver<'a> {
1380
1389
/// `use` injections for proc macros wrongly imported with #[macro_use]
1381
1390
proc_mac_errors : Vec < macros:: ProcMacError > ,
1382
1391
1383
- gated_errors : FxHashSet < Span > ,
1384
1392
disallowed_shadowing : Vec < & ' a LegacyBinding < ' a > > ,
1385
1393
1386
1394
arenas : & ' a ResolverArenas < ' a > ,
1387
1395
dummy_binding : & ' a NameBinding < ' a > ,
1388
- /// true if `#![feature(use_extern_macros)]`
1389
- use_extern_macros : bool ,
1390
1396
1391
1397
crate_loader : & ' a mut CrateLoader ,
1392
1398
macro_names : FxHashSet < Ident > ,
@@ -1396,7 +1402,6 @@ pub struct Resolver<'a> {
1396
1402
macro_map : FxHashMap < DefId , Lrc < SyntaxExtension > > ,
1397
1403
macro_defs : FxHashMap < Mark , DefId > ,
1398
1404
local_macro_def_scopes : FxHashMap < NodeId , Module < ' a > > ,
1399
- macro_exports : Vec < Export > ,
1400
1405
pub whitelisted_legacy_custom_derives : Vec < Name > ,
1401
1406
pub found_unresolved_macro : bool ,
1402
1407
@@ -1429,6 +1434,9 @@ pub struct Resolver<'a> {
1429
1434
1430
1435
/// Only supposed to be used by rustdoc, otherwise should be false.
1431
1436
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 > ,
1432
1440
}
1433
1441
1434
1442
/// Nothing really interesting here, it just provides memory for the rest of the crate.
@@ -1698,7 +1706,6 @@ impl<'a> Resolver<'a> {
1698
1706
ambiguity_errors : Vec :: new ( ) ,
1699
1707
use_injections : Vec :: new ( ) ,
1700
1708
proc_mac_errors : Vec :: new ( ) ,
1701
- gated_errors : FxHashSet ( ) ,
1702
1709
disallowed_shadowing : Vec :: new ( ) ,
1703
1710
1704
1711
arenas,
@@ -1707,19 +1714,15 @@ impl<'a> Resolver<'a> {
1707
1714
expansion : Mark :: root ( ) ,
1708
1715
span : DUMMY_SP ,
1709
1716
vis : ty:: Visibility :: Public ,
1717
+ is_macro_export : false ,
1710
1718
} ) ,
1711
1719
1712
- // The `proc_macro` and `decl_macro` features imply `use_extern_macros`
1713
- use_extern_macros :
1714
- features. use_extern_macros || features. proc_macro || features. decl_macro ,
1715
-
1716
1720
crate_loader,
1717
1721
macro_names : FxHashSet ( ) ,
1718
1722
global_macros : FxHashMap ( ) ,
1719
1723
all_macros : FxHashMap ( ) ,
1720
1724
lexical_macro_resolutions : Vec :: new ( ) ,
1721
1725
macro_map : FxHashMap ( ) ,
1722
- macro_exports : Vec :: new ( ) ,
1723
1726
invocations,
1724
1727
macro_defs,
1725
1728
local_macro_def_scopes : FxHashMap ( ) ,
@@ -1734,6 +1737,7 @@ impl<'a> Resolver<'a> {
1734
1737
current_type_ascription : Vec :: new ( ) ,
1735
1738
injected_crate : None ,
1736
1739
ignore_extern_prelude_feature : false ,
1740
+ unresolved_invocations_macro_export : FxHashSet ( ) ,
1737
1741
}
1738
1742
}
1739
1743
@@ -1753,9 +1757,7 @@ impl<'a> Resolver<'a> {
1753
1757
fn per_ns < F : FnMut ( & mut Self , Namespace ) > ( & mut self , mut f : F ) {
1754
1758
f ( self , TypeNS ) ;
1755
1759
f ( self , ValueNS ) ;
1756
- if self . use_extern_macros {
1757
- f ( self , MacroNS ) ;
1758
- }
1760
+ f ( self , MacroNS ) ;
1759
1761
}
1760
1762
1761
1763
fn macro_def ( & self , mut ctxt : SyntaxContext ) -> DefId {
@@ -1807,6 +1809,7 @@ impl<'a> Resolver<'a> {
1807
1809
NameBindingKind :: Ambiguity { b1, b2 } => {
1808
1810
self . ambiguity_errors . push ( AmbiguityError {
1809
1811
span, name : ident. name , lexical : false , b1, b2,
1812
+ kind : AmbiguityErrorKind :: RecordUse
1810
1813
} ) ;
1811
1814
true
1812
1815
}
@@ -1967,7 +1970,6 @@ impl<'a> Resolver<'a> {
1967
1970
module : Module < ' a > ,
1968
1971
mut ident : Ident ,
1969
1972
ns : Namespace ,
1970
- ignore_unresolved_invocations : bool ,
1971
1973
record_used : bool ,
1972
1974
span : Span )
1973
1975
-> Result < & ' a NameBinding < ' a > , Determinacy > {
@@ -1977,7 +1979,7 @@ impl<'a> Resolver<'a> {
1977
1979
self . current_module = self . macro_def_scope ( def) ;
1978
1980
}
1979
1981
let result = self . resolve_ident_in_module_unadjusted (
1980
- module, ident, ns, ignore_unresolved_invocations , record_used, span,
1982
+ module, ident, ns, false , record_used, span,
1981
1983
) ;
1982
1984
self . current_module = orig_current_module;
1983
1985
result
@@ -2470,7 +2472,7 @@ impl<'a> Resolver<'a> {
2470
2472
// If there is a TraitRef in scope for an impl, then the method must be in the
2471
2473
// trait.
2472
2474
if let Some ( ( module, _) ) = self . current_trait_ref {
2473
- 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 ( ) {
2474
2476
let path = & self . current_trait_ref . as_ref ( ) . unwrap ( ) . 1 . path ;
2475
2477
resolve_error ( self , span, err ( ident. name , & path_names_to_string ( path) ) ) ;
2476
2478
}
@@ -3420,7 +3422,7 @@ impl<'a> Resolver<'a> {
3420
3422
}
3421
3423
3422
3424
let binding = if let Some ( module) = module {
3423
- 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)
3424
3426
} else if opt_ns == Some ( MacroNS ) {
3425
3427
self . resolve_lexical_macro_path_segment ( ident, ns, record_used, path_span)
3426
3428
. map ( MacroBinding :: binding)
@@ -3714,7 +3716,7 @@ impl<'a> Resolver<'a> {
3714
3716
// Look for associated items in the current trait.
3715
3717
if let Some ( ( module, _) ) = self . current_trait_ref {
3716
3718
if let Ok ( binding) =
3717
- self . resolve_ident_in_module ( module, ident, ns, false , false , module. span ) {
3719
+ self . resolve_ident_in_module ( module, ident, ns, false , module. span ) {
3718
3720
let def = binding. def ( ) ;
3719
3721
if filter_fn ( def) {
3720
3722
return Some ( if self . has_self . contains ( & def. def_id ( ) ) {
@@ -4027,7 +4029,7 @@ impl<'a> Resolver<'a> {
4027
4029
let mut found_traits = Vec :: new ( ) ;
4028
4030
// Look for the current trait.
4029
4031
if let Some ( ( module, _) ) = self . current_trait_ref {
4030
- 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 ( ) {
4031
4033
let def_id = module. def_id ( ) . unwrap ( ) ;
4032
4034
found_traits. push ( TraitCandidate { def_id : def_id, import_id : None } ) ;
4033
4035
}
@@ -4300,7 +4302,7 @@ impl<'a> Resolver<'a> {
4300
4302
self . report_proc_macro_import ( krate) ;
4301
4303
let mut reported_spans = FxHashSet ( ) ;
4302
4304
4303
- for & AmbiguityError { span, name, b1, b2, lexical } in & self . ambiguity_errors {
4305
+ for & AmbiguityError { span, name, b1, b2, lexical, kind } in & self . ambiguity_errors {
4304
4306
if !reported_spans. insert ( span) { continue }
4305
4307
let participle = |binding : & NameBinding | {
4306
4308
if binding. is_import ( ) { "imported" } else { "defined" }
@@ -4317,7 +4319,8 @@ impl<'a> Resolver<'a> {
4317
4319
if b1. is_import( ) { "imports" } else { "items" } )
4318
4320
} ;
4319
4321
4320
- 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) ;
4321
4324
err. span_note ( b1. span , & msg1) ;
4322
4325
match b2. def ( ) {
4323
4326
Def :: Macro ( ..) if b2. span . is_dummy ( ) =>
0 commit comments