1515// each trait in the system to its implementations.
1616
1717
18- use metadata:: csearch:: { each_impl, get_impl_trait} ;
18+ use metadata:: csearch:: { each_impl, get_impl_trait, each_implementation_for_trait } ;
1919use metadata:: csearch;
2020use middle:: ty:: get;
2121use middle:: ty:: { ImplContainer , lookup_item_type, subst} ;
@@ -434,7 +434,7 @@ impl CoherenceChecker {
434434
435435 pub fn check_implementation_coherence_of ( & self , trait_def_id : DefId ) {
436436 // Unify pairs of polytypes.
437- self . iter_impls_of_trait ( trait_def_id, |a| {
437+ self . iter_impls_of_trait_local ( trait_def_id, |a| {
438438 let implementation_a = a;
439439 let polytype_a =
440440 self . get_self_type_for_implementation ( implementation_a) ;
@@ -452,19 +452,41 @@ impl CoherenceChecker {
452452 if self . polytypes_unify ( polytype_a. clone ( ) , polytype_b) {
453453 let session = self . crate_context . tcx . sess ;
454454 session. span_err (
455- self . span_of_impl ( implementation_b ) ,
455+ self . span_of_impl ( implementation_a ) ,
456456 format ! ( "conflicting implementations for trait `{}`" ,
457457 ty:: item_path_str( self . crate_context. tcx,
458458 trait_def_id) ) ) ;
459- session. span_note ( self . span_of_impl ( implementation_a) ,
460- "note conflicting implementation here" ) ;
459+ if implementation_b. did . crate == LOCAL_CRATE {
460+ session. span_note ( self . span_of_impl ( implementation_b) ,
461+ "note conflicting implementation here" ) ;
462+ } else {
463+ let crate_store = self . crate_context . tcx . sess . cstore ;
464+ let cdata = crate_store. get_crate_data ( implementation_b. did . crate ) ;
465+ session. note (
466+ "conflicting implementation in crate `" + cdata. name + "`" ) ;
467+ }
461468 }
462469 }
463470 } )
464471 } )
465472 }
466473
467474 pub fn iter_impls_of_trait ( & self , trait_def_id : DefId , f : |@Impl |) {
475+ self . iter_impls_of_trait_local ( trait_def_id, |x| f ( x) ) ;
476+
477+ if trait_def_id. crate == LOCAL_CRATE {
478+ return ;
479+ }
480+
481+ let crate_store = self . crate_context . tcx . sess . cstore ;
482+ csearch:: each_implementation_for_trait ( crate_store, trait_def_id, |impl_def_id| {
483+ let implementation = @csearch:: get_impl ( self . crate_context . tcx , impl_def_id) ;
484+ let _ = lookup_item_type ( self . crate_context . tcx , implementation. did ) ;
485+ f ( implementation) ;
486+ } ) ;
487+ }
488+
489+ pub fn iter_impls_of_trait_local ( & self , trait_def_id : DefId , f : |@Impl |) {
468490 let trait_impls = self . crate_context . tcx . trait_impls . borrow ( ) ;
469491 match trait_impls. get ( ) . find ( & trait_def_id) {
470492 Some ( impls) => {
0 commit comments