Skip to content

Commit 75884d4

Browse files
committed
Filter out trait predicate in compare_predicate_entailment
1 parent b914418 commit 75884d4

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/librustc/traits/select.rs

+17
Original file line numberDiff line numberDiff line change
@@ -1164,11 +1164,28 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
11641164
}
11651165
}).collect();
11661166

1167+
debug!("winnowed to {} candidates for {:?}: {:?}",
1168+
candidates.len(),
1169+
stack,
1170+
candidates);
1171+
11671172
// If there are STILL multiple candidate, we can further
11681173
// reduce the list by dropping duplicates -- including
11691174
// resolving specializations.
11701175
if candidates.len() > 1 {
11711176
let mut i = 0;
1177+
//candidates.retain(|c| {
1178+
// match c.candidate {
1179+
// ParamCandidate(poly_trait_ref) => {
1180+
// if poly_trait_ref == stack.obligation.predicate.map_bound(|x| x.trait_ref) {
1181+
// debug!("Dropping candidate (== obligation): {:?}", c);
1182+
// return false;
1183+
// }
1184+
// }
1185+
// _ => {}
1186+
// }
1187+
// true
1188+
//});
11721189
while i < candidates.len() {
11731190
let is_dup =
11741191
(0..candidates.len())

src/librustc_typeck/check/compare_method.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,22 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
181181
let impl_m_generics = tcx.generics_of(impl_m.def_id);
182182
let trait_m_generics = tcx.generics_of(trait_m.def_id);
183183
let impl_m_predicates = tcx.predicates_of(impl_m.def_id);
184-
let trait_m_predicates = tcx.predicates_of(trait_m.def_id);
184+
let mut trait_m_predicates = tcx.predicates_of(trait_m.def_id);
185+
186+
if let Some(trait_def_id) = trait_m_predicates.parent {
187+
trait_m_predicates.predicates.retain(|pred| {
188+
match pred {
189+
ty::Predicate::Trait(trait_ref) => {
190+
if trait_ref.def_id() == trait_def_id {
191+
false
192+
} else {
193+
true
194+
}
195+
}
196+
_ => true
197+
}
198+
});
199+
}
185200

186201
// Check region bounds.
187202
check_region_bounds_on_impl_method(tcx,
@@ -212,6 +227,8 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
212227
hybrid_preds.predicates
213228
.extend(trait_m_predicates.instantiate_own(tcx, trait_to_skol_substs).predicates);
214229

230+
debug!("compare_impl_method: impl_bounds+trait_bounds={:?}", hybrid_preds);
231+
215232
// Construct trait parameter environment and then shift it into the skolemized viewpoint.
216233
// The key step here is to update the caller_bounds's predicates to be
217234
// the new hybrid bounds we computed.

0 commit comments

Comments
 (0)