15
15
// each trait in the system to its implementations.
16
16
17
17
18
- use metadata:: csearch:: { each_impl, get_impl_trait} ;
18
+ use metadata:: csearch:: { each_impl, get_impl_trait, each_implementation_for_trait } ;
19
19
use metadata:: csearch;
20
20
use middle:: ty:: get;
21
21
use middle:: ty:: { ImplContainer , lookup_item_type, subst} ;
@@ -434,7 +434,7 @@ impl CoherenceChecker {
434
434
435
435
pub fn check_implementation_coherence_of ( & self , trait_def_id : DefId ) {
436
436
// 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| {
438
438
let implementation_a = a;
439
439
let polytype_a =
440
440
self . get_self_type_for_implementation ( implementation_a) ;
@@ -452,19 +452,41 @@ impl CoherenceChecker {
452
452
if self . polytypes_unify ( polytype_a. clone ( ) , polytype_b) {
453
453
let session = self . crate_context . tcx . sess ;
454
454
session. span_err (
455
- self . span_of_impl ( implementation_b ) ,
455
+ self . span_of_impl ( implementation_a ) ,
456
456
format ! ( "conflicting implementations for trait `{}`" ,
457
457
ty:: item_path_str( self . crate_context. tcx,
458
458
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
+ }
461
468
}
462
469
}
463
470
} )
464
471
} )
465
472
}
466
473
467
474
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 |) {
468
490
let trait_impls = self . crate_context . tcx . trait_impls . borrow ( ) ;
469
491
match trait_impls. get ( ) . find ( & trait_def_id) {
470
492
Some ( impls) => {
0 commit comments