@@ -3450,11 +3450,11 @@ impl<'a> Resolver<'a> {
3450
3450
parent : Module ,
3451
3451
ident : Ident ,
3452
3452
ns : Namespace ,
3453
- binding : & NameBinding ,
3453
+ new_binding : & NameBinding ,
3454
3454
old_binding : & NameBinding ) {
3455
3455
// Error on the second of two conflicting names
3456
- if old_binding. span . lo > binding . span . lo {
3457
- return self . report_conflict ( parent, ident, ns, old_binding, binding ) ;
3456
+ if old_binding. span . lo > new_binding . span . lo {
3457
+ return self . report_conflict ( parent, ident, ns, old_binding, new_binding ) ;
3458
3458
}
3459
3459
3460
3460
let container = match parent. kind {
@@ -3464,49 +3464,65 @@ impl<'a> Resolver<'a> {
3464
3464
_ => "enum" ,
3465
3465
} ;
3466
3466
3467
- let ( participle , noun ) = match old_binding. is_import ( ) {
3468
- true => ( "imported" , " import") ,
3469
- false => ( "defined" , " definition") ,
3467
+ let old_noun = match old_binding. is_import ( ) {
3468
+ true => " import",
3469
+ false => " definition",
3470
3470
} ;
3471
3471
3472
- let ( name, span) = ( ident. name , binding. span ) ;
3472
+ let new_participle = match new_binding. is_import ( ) {
3473
+ true => "imported" ,
3474
+ false => "defined" ,
3475
+ } ;
3476
+
3477
+ let ( name, span) = ( ident. name , new_binding. span ) ;
3473
3478
3474
3479
if let Some ( s) = self . name_already_seen . get ( & name) {
3475
3480
if s == & span {
3476
3481
return ;
3477
3482
}
3478
3483
}
3479
3484
3480
- let msg = {
3481
- let kind = match ( ns, old_binding. module ( ) ) {
3482
- ( ValueNS , _) => "a value" ,
3483
- ( MacroNS , _) => "a macro" ,
3484
- ( TypeNS , _) if old_binding. is_extern_crate ( ) => "an extern crate" ,
3485
- ( TypeNS , Some ( module) ) if module. is_normal ( ) => "a module" ,
3486
- ( TypeNS , Some ( module) ) if module. is_trait ( ) => "a trait" ,
3487
- ( TypeNS , _) => "a type" ,
3488
- } ;
3489
- format ! ( "{} named `{}` has already been {} in this {}" ,
3490
- kind, name, participle, container)
3485
+ let old_kind = match ( ns, old_binding. module ( ) ) {
3486
+ ( ValueNS , _) => "value" ,
3487
+ ( MacroNS , _) => "macro" ,
3488
+ ( TypeNS , _) if old_binding. is_extern_crate ( ) => "extern crate" ,
3489
+ ( TypeNS , Some ( module) ) if module. is_normal ( ) => "module" ,
3490
+ ( TypeNS , Some ( module) ) if module. is_trait ( ) => "trait" ,
3491
+ ( TypeNS , _) => "type" ,
3492
+ } ;
3493
+
3494
+ let namespace = match ns {
3495
+ ValueNS => "value" ,
3496
+ MacroNS => "macro" ,
3497
+ TypeNS => "type" ,
3491
3498
} ;
3492
3499
3493
- let mut err = match ( old_binding. is_extern_crate ( ) , binding. is_extern_crate ( ) ) {
3500
+ let msg = format ! ( "the name `{}` is defined multiple times" , name) ;
3501
+
3502
+ let mut err = match ( old_binding. is_extern_crate ( ) , new_binding. is_extern_crate ( ) ) {
3494
3503
( true , true ) => struct_span_err ! ( self . session, span, E0259 , "{}" , msg) ,
3495
- ( true , _) | ( _, true ) => match binding . is_import ( ) && old_binding. is_import ( ) {
3504
+ ( true , _) | ( _, true ) => match new_binding . is_import ( ) && old_binding. is_import ( ) {
3496
3505
true => struct_span_err ! ( self . session, span, E0254 , "{}" , msg) ,
3497
3506
false => struct_span_err ! ( self . session, span, E0260 , "{}" , msg) ,
3498
3507
} ,
3499
- _ => match ( old_binding. is_import ( ) , binding . is_import ( ) ) {
3508
+ _ => match ( old_binding. is_import ( ) , new_binding . is_import ( ) ) {
3500
3509
( false , false ) => struct_span_err ! ( self . session, span, E0428 , "{}" , msg) ,
3501
3510
( true , true ) => struct_span_err ! ( self . session, span, E0252 , "{}" , msg) ,
3502
3511
_ => struct_span_err ! ( self . session, span, E0255 , "{}" , msg) ,
3503
3512
} ,
3504
3513
} ;
3505
3514
3506
- err. span_label ( span, format ! ( "`{}` already {}" , name, participle) ) ;
3515
+ err. note ( & format ! ( "`{}` must be defined only once in the {} namespace of this {}" ,
3516
+ name,
3517
+ namespace,
3518
+ container) ) ;
3519
+
3520
+ err. span_label ( span, format ! ( "`{}` re{} here" , name, new_participle) ) ;
3507
3521
if old_binding. span != syntax_pos:: DUMMY_SP {
3508
- err. span_label ( old_binding. span , format ! ( "previous {} of `{}` here" , noun, name) ) ;
3522
+ err. span_label ( old_binding. span , format ! ( "previous {} of the {} `{}` here" ,
3523
+ old_noun, old_kind, name) ) ;
3509
3524
}
3525
+
3510
3526
err. emit ( ) ;
3511
3527
self . name_already_seen . insert ( name, span) ;
3512
3528
}
0 commit comments