Skip to content

Commit 89af153

Browse files
committed
Handle trait objects
1 parent 8b16eb8 commit 89af153

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

src/librustc/middle/infer/error_reporting.rs

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ use rustc_front::hir;
7878
use rustc_front::print::pprust;
7979

8080
use middle::def;
81+
use middle::def_id::DefId;
8182
use middle::infer;
8283
use middle::region;
8384
use middle::subst;
@@ -497,6 +498,25 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
497498

498499
/// Adds a note if the types come from similarly named crates
499500
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+
};
500520
match *terr {
501521
ty::TypeError::Sorts(ref exp_found) => {
502522
// 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> {
506526
(&ty::TyStruct(ref exp_adt, _), &ty::TyStruct(ref found_adt, _)) |
507527
(&ty::TyEnum(ref exp_adt, _), &ty::TyStruct(ref found_adt, _)) |
508528
(&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);
523530
},
524531
_ => ()
525532
}
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+
},
527538
_ => () // FIXME(Manishearth) handle traits and stuff
528539
}
529540
}

0 commit comments

Comments
 (0)