@@ -75,7 +75,7 @@ use std::mem::replace;
75
75
use std:: rc:: Rc ;
76
76
77
77
use resolve_imports:: { ImportDirective , ImportDirectiveSubclass , NameResolution , ImportResolver } ;
78
- use macros:: { InvocationData , LegacyBinding , LegacyScope } ;
78
+ use macros:: { InvocationData , LegacyBinding , LegacyScope , MacroBinding } ;
79
79
80
80
// NB: This module needs to be declared first so diagnostics are
81
81
// registered before they are used.
@@ -1174,7 +1174,7 @@ pub struct Resolver<'a> {
1174
1174
1175
1175
crate_loader : & ' a mut CrateLoader ,
1176
1176
macro_names : FxHashSet < Name > ,
1177
- builtin_macros : FxHashMap < Name , & ' a NameBinding < ' a > > ,
1177
+ global_macros : FxHashMap < Name , & ' a NameBinding < ' a > > ,
1178
1178
lexical_macro_resolutions : Vec < ( Name , & ' a Cell < LegacyScope < ' a > > ) > ,
1179
1179
macro_map : FxHashMap < DefId , Rc < SyntaxExtension > > ,
1180
1180
macro_defs : FxHashMap < Mark , DefId > ,
@@ -1372,7 +1372,7 @@ impl<'a> Resolver<'a> {
1372
1372
1373
1373
crate_loader : crate_loader,
1374
1374
macro_names : FxHashSet ( ) ,
1375
- builtin_macros : FxHashMap ( ) ,
1375
+ global_macros : FxHashMap ( ) ,
1376
1376
lexical_macro_resolutions : Vec :: new ( ) ,
1377
1377
macro_map : FxHashMap ( ) ,
1378
1378
macro_exports : Vec :: new ( ) ,
@@ -2429,9 +2429,9 @@ impl<'a> Resolver<'a> {
2429
2429
} ;
2430
2430
}
2431
2431
}
2432
- let is_builtin = self . builtin_macros . get ( & path[ 0 ] . name ) . cloned ( )
2432
+ let is_global = self . global_macros . get ( & path[ 0 ] . name ) . cloned ( )
2433
2433
. map ( |binding| binding. get_macro ( self ) . kind ( ) == MacroKind :: Bang ) . unwrap_or ( false ) ;
2434
- if primary_ns != MacroNS && ( is_builtin || self . macro_names . contains ( & path[ 0 ] . name ) ) {
2434
+ if primary_ns != MacroNS && ( is_global || self . macro_names . contains ( & path[ 0 ] . name ) ) {
2435
2435
// Return some dummy definition, it's enough for error reporting.
2436
2436
return Some (
2437
2437
PathResolution :: new ( Def :: Macro ( DefId :: local ( CRATE_DEF_INDEX ) , MacroKind :: Bang ) )
@@ -2566,6 +2566,7 @@ impl<'a> Resolver<'a> {
2566
2566
self . resolve_ident_in_module ( module, ident, ns, false , record_used)
2567
2567
} else if opt_ns == Some ( MacroNS ) {
2568
2568
self . resolve_lexical_macro_path_segment ( ident, ns, record_used)
2569
+ . map ( MacroBinding :: binding)
2569
2570
} else {
2570
2571
match self . resolve_ident_in_lexical_scope ( ident, ns, record_used) {
2571
2572
Some ( LexicalScopeBinding :: Item ( binding) ) => Ok ( binding) ,
@@ -3223,7 +3224,7 @@ impl<'a> Resolver<'a> {
3223
3224
} ;
3224
3225
let msg1 = format ! ( "`{}` could refer to the name {} here" , name, participle( b1) ) ;
3225
3226
let msg2 = format ! ( "`{}` could also refer to the name {} here" , name, participle( b2) ) ;
3226
- let note = if !lexical && b1. is_glob_import ( ) {
3227
+ let note = if b1 . expansion == Mark :: root ( ) || !lexical && b1. is_glob_import ( ) {
3227
3228
format ! ( "consider adding an explicit import of `{}` to disambiguate" , name)
3228
3229
} else if let Def :: Macro ( ..) = b1. def ( ) {
3229
3230
format ! ( "macro-expanded {} do not shadow" ,
@@ -3243,11 +3244,15 @@ impl<'a> Resolver<'a> {
3243
3244
let msg = format ! ( "`{}` is ambiguous" , name) ;
3244
3245
self . session . add_lint ( lint:: builtin:: LEGACY_IMPORTS , id, span, msg) ;
3245
3246
} else {
3246
- self . session . struct_span_err ( span, & format ! ( "`{}` is ambiguous" , name) )
3247
- . span_note ( b1. span , & msg1)
3248
- . span_note ( b2. span , & msg2)
3249
- . note ( & note)
3250
- . emit ( ) ;
3247
+ let mut err =
3248
+ self . session . struct_span_err ( span, & format ! ( "`{}` is ambiguous" , name) ) ;
3249
+ err. span_note ( b1. span , & msg1) ;
3250
+ match b2. def ( ) {
3251
+ Def :: Macro ( ..) if b2. span == DUMMY_SP =>
3252
+ err. note ( & format ! ( "`{}` is also a builtin macro" , name) ) ,
3253
+ _ => err. span_note ( b2. span , & msg2) ,
3254
+ } ;
3255
+ err. note ( & note) . emit ( ) ;
3251
3256
}
3252
3257
}
3253
3258
@@ -3361,22 +3366,21 @@ impl<'a> Resolver<'a> {
3361
3366
if self . proc_macro_enabled { return ; }
3362
3367
3363
3368
for attr in attrs {
3364
- let name = unwrap_or ! ( attr. name( ) , continue ) ;
3365
- let maybe_binding = self . builtin_macros . get ( & name) . cloned ( ) . or_else ( || {
3366
- let ident = Ident :: with_empty_ctxt ( name) ;
3367
- self . resolve_lexical_macro_path_segment ( ident, MacroNS , None ) . ok ( )
3368
- } ) ;
3369
-
3370
- if let Some ( binding) = maybe_binding {
3371
- if let SyntaxExtension :: AttrProcMacro ( ..) = * binding. get_macro ( self ) {
3369
+ if attr. path . segments . len ( ) > 1 {
3370
+ continue
3371
+ }
3372
+ let ident = attr. path . segments [ 0 ] . identifier ;
3373
+ let result = self . resolve_lexical_macro_path_segment ( ident, MacroNS , None ) ;
3374
+ if let Ok ( binding) = result {
3375
+ if let SyntaxExtension :: AttrProcMacro ( ..) = * binding. binding ( ) . get_macro ( self ) {
3372
3376
attr:: mark_known ( attr) ;
3373
3377
3374
3378
let msg = "attribute procedural macros are experimental" ;
3375
3379
let feature = "proc_macro" ;
3376
3380
3377
3381
feature_err ( & self . session . parse_sess , feature,
3378
3382
attr. span , GateIssue :: Language , msg)
3379
- . span_note ( binding. span , "procedural macro imported here" )
3383
+ . span_note ( binding. span ( ) , "procedural macro imported here" )
3380
3384
. emit ( ) ;
3381
3385
}
3382
3386
}
0 commit comments