@@ -3450,11 +3450,11 @@ impl<'a> Resolver<'a> {
34503450 parent : Module ,
34513451 ident : Ident ,
34523452 ns : Namespace ,
3453- binding : & NameBinding ,
3453+ new_binding : & NameBinding ,
34543454 old_binding : & NameBinding ) {
34553455 // 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 ) ;
34583458 }
34593459
34603460 let container = match parent. kind {
@@ -3464,49 +3464,65 @@ impl<'a> Resolver<'a> {
34643464 _ => "enum" ,
34653465 } ;
34663466
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",
34703470 } ;
34713471
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 ) ;
34733478
34743479 if let Some ( s) = self . name_already_seen . get ( & name) {
34753480 if s == & span {
34763481 return ;
34773482 }
34783483 }
34793484
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" ,
34913498 } ;
34923499
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 ( ) ) {
34943503 ( 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 ( ) {
34963505 true => struct_span_err ! ( self . session, span, E0254 , "{}" , msg) ,
34973506 false => struct_span_err ! ( self . session, span, E0260 , "{}" , msg) ,
34983507 } ,
3499- _ => match ( old_binding. is_import ( ) , binding . is_import ( ) ) {
3508+ _ => match ( old_binding. is_import ( ) , new_binding . is_import ( ) ) {
35003509 ( false , false ) => struct_span_err ! ( self . session, span, E0428 , "{}" , msg) ,
35013510 ( true , true ) => struct_span_err ! ( self . session, span, E0252 , "{}" , msg) ,
35023511 _ => struct_span_err ! ( self . session, span, E0255 , "{}" , msg) ,
35033512 } ,
35043513 } ;
35053514
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) ) ;
35073521 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) ) ;
35093524 }
3525+
35103526 err. emit ( ) ;
35113527 self . name_already_seen . insert ( name, span) ;
35123528 }
0 commit comments