Skip to content

Commit 7b48b58

Browse files
author
Ariel Ben-Yehuda
committed
very buggy
1 parent dfa094a commit 7b48b58

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/librustc/middle/traits/select.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -678,9 +678,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
678678
candidates.retain(|c| self.winnow_candidate(stack, c).may_apply())
679679
}
680680

681-
// If there are STILL multiple candidate, we can further reduce
682-
// the list by dropping duplicates.
683-
if candidates.len() > 1 {
681+
// If the predicate is fully known, there should be only one
682+
// matching candidate by coherence. However, there may also be
683+
// other candidates from impls (see the doc-comment for
684+
// Candidate). Pick one candidate to use. This is somewhat
685+
// wrong around regions.
686+
if candidates.len() > 1 && !stack.obligation.predicate.has_ty_infer() {
684687
let mut i = 0;
685688
while i < candidates.len() {
686689
let is_dup =
@@ -817,9 +820,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
817820

818821
match *candidate {
819822
Ok(Some(_)) | Err(_) => true,
820-
Ok(None) => {
821-
cache_fresh_trait_pred.0.input_types().iter().any(|&t| ty::type_has_ty_infer(t))
822-
}
823+
Ok(None) => cache_fresh_trait_pred.has_ty_infer()
823824
}
824825
}
825826

src/librustc/middle/ty.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1986,6 +1986,10 @@ impl<'tcx> PolyTraitPredicate<'tcx> {
19861986
pub fn def_id(&self) -> ast::DefId {
19871987
self.0.def_id()
19881988
}
1989+
1990+
pub fn has_ty_infer(&self) -> bool {
1991+
self.0.input_types().iter().any(|&t| ty::type_has_ty_infer(t))
1992+
}
19891993
}
19901994

19911995
#[derive(Clone, PartialEq, Eq, Hash, Debug)]

0 commit comments

Comments
 (0)