@@ -78,6 +78,7 @@ use rustc_front::hir;
78
78
use rustc_front:: print:: pprust;
79
79
80
80
use middle:: def;
81
+ use middle:: def_id:: DefId ;
81
82
use middle:: infer;
82
83
use middle:: region;
83
84
use middle:: subst;
@@ -497,6 +498,25 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
497
498
498
499
/// Adds a note if the types come from similarly named crates
499
500
fn check_and_note_conflicting_crates ( & self , terr : & ty:: TypeError < ' tcx > , sp : Span ) {
501
+ let report_path_match = |did1 : DefId , did2 : DefId | {
502
+ // Only external crates, if either is from a local
503
+ // module we could have false positives
504
+ if !( did1. is_local ( ) || did2. is_local ( ) ) {
505
+ let exp_path = self . tcx . with_path ( did1,
506
+ |p| p. map ( |x| x. to_string ( ) )
507
+ . collect :: < Vec < _ > > ( ) ) ;
508
+ let found_path = self . tcx . with_path ( did2,
509
+ |p| p. map ( |x| x. to_string ( ) )
510
+ . collect :: < Vec < _ > > ( ) ) ;
511
+ // We compare strings because PathMod and PathName can be different
512
+ // for imported and non-imported crates
513
+ if exp_path == found_path {
514
+ self . tcx . sess . span_note ( sp, & format ! ( "Perhaps two different versions \
515
+ of crate `{}` are being used?",
516
+ exp_path[ 0 ] ) ) ;
517
+ }
518
+ }
519
+ } ;
500
520
match * terr {
501
521
ty:: TypeError :: Sorts ( ref exp_found) => {
502
522
// if they are both "path types", there's a chance of ambiguity
@@ -506,24 +526,15 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
506
526
( & ty:: TyStruct ( ref exp_adt, _) , & ty:: TyStruct ( ref found_adt, _) ) |
507
527
( & ty:: TyEnum ( ref exp_adt, _) , & ty:: TyStruct ( ref found_adt, _) ) |
508
528
( & ty:: TyStruct ( ref exp_adt, _) , & ty:: TyEnum ( ref found_adt, _) ) => {
509
- // Only external crates, if either is from a local
510
- // module we could have false positives
511
- if exp_adt. did . is_local ( ) || found_adt. did . is_local ( ) {
512
- return
513
- }
514
- let exp_path = self . tcx . with_path ( exp_adt. did ,
515
- |p| p. collect :: < Vec < _ > > ( ) ) ;
516
- let found_path = self . tcx . with_path ( exp_adt. did ,
517
- |p| p. collect :: < Vec < _ > > ( ) ) ;
518
- if exp_path == found_path {
519
- self . tcx . sess . span_note ( sp, & format ! ( "Perhaps two different versions \
520
- of crate `{}` are being used?",
521
- exp_path[ 0 ] ) ) ;
522
- }
529
+ report_path_match ( exp_adt. did , found_adt. did ) ;
523
530
} ,
524
531
_ => ( )
525
532
}
526
- }
533
+ } ,
534
+ ty:: TypeError :: Traits ( ref exp_found) => {
535
+ self . tcx . sess . note ( "errrr0" ) ;
536
+ report_path_match ( exp_found. expected , exp_found. found ) ;
537
+ } ,
527
538
_ => ( ) // FIXME(Manishearth) handle traits and stuff
528
539
}
529
540
}
0 commit comments