@@ -1065,6 +1065,7 @@ pub struct Resolver<'a> {
1065
1065
pub maybe_unused_trait_imports : NodeSet ,
1066
1066
1067
1067
privacy_errors : Vec < PrivacyError < ' a > > ,
1068
+ ambiguity_errors : Vec < ( Span , Name , & ' a NameBinding < ' a > ) > ,
1068
1069
1069
1070
arenas : & ' a ResolverArenas < ' a > ,
1070
1071
dummy_binding : & ' a NameBinding < ' a > ,
@@ -1218,6 +1219,7 @@ impl<'a> Resolver<'a> {
1218
1219
maybe_unused_trait_imports : NodeSet ( ) ,
1219
1220
1220
1221
privacy_errors : Vec :: new ( ) ,
1222
+ ambiguity_errors : Vec :: new ( ) ,
1221
1223
1222
1224
arenas : arenas,
1223
1225
dummy_binding : arenas. alloc_name_binding ( NameBinding {
@@ -1245,7 +1247,7 @@ impl<'a> Resolver<'a> {
1245
1247
visit:: walk_crate ( self , krate) ;
1246
1248
1247
1249
check_unused:: check_crate ( self , krate) ;
1248
- self . report_privacy_errors ( ) ;
1250
+ self . report_errors ( ) ;
1249
1251
}
1250
1252
1251
1253
fn new_module ( & self , parent_link : ParentLink < ' a > , def : Option < Def > , normal_ancestor_id : NodeId )
@@ -1276,14 +1278,8 @@ impl<'a> Resolver<'a> {
1276
1278
self . add_to_glob_map ( directive. id , name) ;
1277
1279
}
1278
1280
1279
- if let Some ( ( b1, b2) ) = binding. ambiguity ( ) {
1280
- let msg1 = format ! ( "`{}` could resolve to the name imported here" , name) ;
1281
- let msg2 = format ! ( "`{}` could also resolve to the name imported here" , name) ;
1282
- self . session . struct_span_err ( span, & format ! ( "`{}` is ambiguous" , name) )
1283
- . span_note ( b1. span , & msg1)
1284
- . span_note ( b2. span , & msg2)
1285
- . note ( & format ! ( "Consider adding an explicit import of `{}` to disambiguate" , name) )
1286
- . emit ( ) ;
1281
+ if binding. ambiguity ( ) . is_some ( ) {
1282
+ self . ambiguity_errors . push ( ( span, name, binding) ) ;
1287
1283
return true ;
1288
1284
}
1289
1285
@@ -3289,9 +3285,21 @@ impl<'a> Resolver<'a> {
3289
3285
vis. is_accessible_from ( module. normal_ancestor_id , self )
3290
3286
}
3291
3287
3292
- fn report_privacy_errors ( & self ) {
3293
- if self . privacy_errors . len ( ) == 0 { return }
3288
+ fn report_errors ( & self ) {
3294
3289
let mut reported_spans = FnvHashSet ( ) ;
3290
+
3291
+ for & ( span, name, binding) in & self . ambiguity_errors {
3292
+ if !reported_spans. insert ( span) { continue }
3293
+ let ( b1, b2) = binding. ambiguity ( ) . unwrap ( ) ;
3294
+ let msg1 = format ! ( "`{}` could resolve to the name imported here" , name) ;
3295
+ let msg2 = format ! ( "`{}` could also resolve to the name imported here" , name) ;
3296
+ self . session . struct_span_err ( span, & format ! ( "`{}` is ambiguous" , name) )
3297
+ . span_note ( b1. span , & msg1)
3298
+ . span_note ( b2. span , & msg2)
3299
+ . note ( & format ! ( "Consider adding an explicit import of `{}` to disambiguate" , name) )
3300
+ . emit ( ) ;
3301
+ }
3302
+
3295
3303
for & PrivacyError ( span, name, binding) in & self . privacy_errors {
3296
3304
if !reported_spans. insert ( span) { continue }
3297
3305
if binding. is_extern_crate ( ) {
0 commit comments