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