Skip to content

Commit f291318

Browse files
committed
enable coinductive reasoning for structural traits, this is
potentially just a stopgap measure
1 parent ee8f648 commit f291318

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/librustc/middle/traits/fulfill.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,19 @@ fn process_predicate1<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx>,
368368
let obligation = &pending_obligation.obligation;
369369
match obligation.predicate {
370370
ty::Predicate::Trait(ref data) => {
371+
// For defaulted traits, we use a co-inductive strategy to
372+
// solve, so that recursion is ok.
373+
if selcx.tcx().trait_has_default_impl(data.def_id()) {
374+
debug!("process_predicate: trait has default impl");
375+
for bt_obligation in backtrace {
376+
debug!("process_predicate: bt_obligation = {:?}", bt_obligation.obligation);
377+
if bt_obligation.obligation.predicate == obligation.predicate {
378+
debug!("process_predicate: found a match!");
379+
return Ok(Some(vec![]));
380+
}
381+
}
382+
}
383+
371384
let trait_obligation = obligation.with(data.clone());
372385
match selcx.select(&trait_obligation) {
373386
Ok(Some(vtable)) => {

0 commit comments

Comments
 (0)