@@ -65,7 +65,7 @@ use syntax::ast::{Item, ItemKind, ImplItem, ImplItemKind};
65
65
use syntax:: ast:: { Local , Mutability , Pat , PatKind , Path } ;
66
66
use syntax:: ast:: { PathSegment , PathParameters , QSelf , TraitItemKind , TraitRef , Ty , TyKind } ;
67
67
68
- use syntax_pos:: { Span , DUMMY_SP } ;
68
+ use syntax_pos:: { Span , DUMMY_SP , MultiSpan } ;
69
69
use errors:: DiagnosticBuilder ;
70
70
71
71
use std:: cell:: { Cell , RefCell } ;
@@ -897,6 +897,7 @@ enum NameBindingKind<'a> {
897
897
Ambiguity {
898
898
b1 : & ' a NameBinding < ' a > ,
899
899
b2 : & ' a NameBinding < ' a > ,
900
+ legacy : bool ,
900
901
}
901
902
}
902
903
@@ -908,13 +909,15 @@ struct AmbiguityError<'a> {
908
909
lexical : bool ,
909
910
b1 : & ' a NameBinding < ' a > ,
910
911
b2 : & ' a NameBinding < ' a > ,
912
+ legacy : bool ,
911
913
}
912
914
913
915
impl < ' a > NameBinding < ' a > {
914
916
fn module ( & self ) -> Option < Module < ' a > > {
915
917
match self . kind {
916
918
NameBindingKind :: Module ( module) => Some ( module) ,
917
919
NameBindingKind :: Import { binding, .. } => binding. module ( ) ,
920
+ NameBindingKind :: Ambiguity { legacy : true , b1, .. } => b1. module ( ) ,
918
921
_ => None ,
919
922
}
920
923
}
@@ -924,6 +927,7 @@ impl<'a> NameBinding<'a> {
924
927
NameBindingKind :: Def ( def) => def,
925
928
NameBindingKind :: Module ( module) => module. def ( ) . unwrap ( ) ,
926
929
NameBindingKind :: Import { binding, .. } => binding. def ( ) ,
930
+ NameBindingKind :: Ambiguity { legacy : true , b1, .. } => b1. def ( ) ,
927
931
NameBindingKind :: Ambiguity { .. } => Def :: Err ,
928
932
}
929
933
}
@@ -1350,11 +1354,14 @@ impl<'a> Resolver<'a> {
1350
1354
self . record_use ( name, ns, binding, span)
1351
1355
}
1352
1356
NameBindingKind :: Import { .. } => false ,
1353
- NameBindingKind :: Ambiguity { b1, b2 } => {
1357
+ NameBindingKind :: Ambiguity { b1, b2, legacy } => {
1354
1358
self . ambiguity_errors . push ( AmbiguityError {
1355
- span : span, name : name, lexical : false , b1 : b1, b2 : b2,
1359
+ span : span, name : name, lexical : false , b1 : b1, b2 : b2, legacy : legacy ,
1356
1360
} ) ;
1357
- true
1361
+ if legacy {
1362
+ self . record_use ( name, ns, b1, span) ;
1363
+ }
1364
+ !legacy
1358
1365
}
1359
1366
_ => false
1360
1367
}
@@ -3064,26 +3071,39 @@ impl<'a> Resolver<'a> {
3064
3071
self . report_shadowing_errors ( ) ;
3065
3072
let mut reported_spans = FxHashSet ( ) ;
3066
3073
3067
- for & AmbiguityError { span, name, b1, b2, lexical } in & self . ambiguity_errors {
3074
+ for & AmbiguityError { span, name, b1, b2, lexical, legacy } in & self . ambiguity_errors {
3068
3075
if !reported_spans. insert ( span) { continue }
3069
3076
let participle = |binding : & NameBinding | {
3070
3077
if binding. is_import ( ) { "imported" } else { "defined" }
3071
3078
} ;
3072
3079
let msg1 = format ! ( "`{}` could resolve to the name {} here" , name, participle( b1) ) ;
3073
3080
let msg2 = format ! ( "`{}` could also resolve to the name {} here" , name, participle( b2) ) ;
3074
- self . session . struct_span_err ( span, & format ! ( "`{}` is ambiguous" , name) )
3075
- . span_note ( b1. span , & msg1)
3076
- . span_note ( b2. span , & msg2)
3077
- . note ( & if !lexical && b1. is_glob_import ( ) {
3078
- format ! ( "consider adding an explicit import of `{}` to disambiguate" , name)
3079
- } else if let Def :: Macro ( ..) = b1. def ( ) {
3080
- format ! ( "macro-expanded {} do not shadow" ,
3081
- if b1. is_import( ) { "macro imports" } else { "macros" } )
3082
- } else {
3083
- format ! ( "macro-expanded {} do not shadow when used in a macro invocation path" ,
3084
- if b1. is_import( ) { "imports" } else { "items" } )
3085
- } )
3086
- . emit ( ) ;
3081
+ let note = if !lexical && b1. is_glob_import ( ) {
3082
+ format ! ( "consider adding an explicit import of `{}` to disambiguate" , name)
3083
+ } else if let Def :: Macro ( ..) = b1. def ( ) {
3084
+ format ! ( "macro-expanded {} do not shadow" ,
3085
+ if b1. is_import( ) { "macro imports" } else { "macros" } )
3086
+ } else {
3087
+ format ! ( "macro-expanded {} do not shadow when used in a macro invocation path" ,
3088
+ if b1. is_import( ) { "imports" } else { "items" } )
3089
+ } ;
3090
+ if legacy {
3091
+ let id = match b2. kind {
3092
+ NameBindingKind :: Import { directive, .. } => directive. id ,
3093
+ _ => unreachable ! ( ) ,
3094
+ } ;
3095
+ let mut span = MultiSpan :: from_span ( span) ;
3096
+ span. push_span_label ( b1. span , msg1) ;
3097
+ span. push_span_label ( b2. span , msg2) ;
3098
+ let msg = format ! ( "`{}` is ambiguous" , name) ;
3099
+ self . session . add_lint ( lint:: builtin:: LEGACY_IMPORTS , id, span, msg) ;
3100
+ } else {
3101
+ self . session . struct_span_err ( span, & format ! ( "`{}` is ambiguous" , name) )
3102
+ . span_note ( b1. span , & msg1)
3103
+ . span_note ( b2. span , & msg2)
3104
+ . note ( & note)
3105
+ . emit ( ) ;
3106
+ }
3087
3107
}
3088
3108
3089
3109
for & PrivacyError ( span, name, binding) in & self . privacy_errors {
0 commit comments