Skip to content

Commit 05c644d

Browse files
committed
---
yaml --- r: 234442 b: refs/heads/tmp c: 89af153 h: refs/heads/master v: v3
1 parent f54634f commit 05c644d

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
2626
refs/heads/beta: d2e13e822a73e0ea46ae9e21afdd3155fc997f6d
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
28-
refs/heads/tmp: 8b16eb832596d305f7da3f88c64aa35762fcba1e
28+
refs/heads/tmp: 89af15322dbca73b098e55bbd283a2d8a254571b
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: ab792abf1fcc28afbd315426213f6428da25c085
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828

branches/tmp/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)