]> git.lizzy.rs Git - rust.git/commitdiff
enable coinductive reasoning for structural traits, this is
authorNiko Matsakis <niko@alum.mit.edu>
Wed, 23 Dec 2015 00:44:48 +0000 (19:44 -0500)
committerNiko Matsakis <niko@alum.mit.edu>
Sat, 16 Jan 2016 10:22:32 +0000 (05:22 -0500)
potentially just a stopgap measure

src/librustc/middle/traits/fulfill.rs

index 7e48f20ce10aae43d72886c252f0817fa073430c..ca2a9f9ca0bf68f5c6b23d29d8b14bc8ae7a6612 100644 (file)
@@ -368,6 +368,19 @@ fn process_predicate1<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx>,
     let obligation = &pending_obligation.obligation;
     match obligation.predicate {
         ty::Predicate::Trait(ref data) => {
+            // For defaulted traits, we use a co-inductive strategy to
+            // solve, so that recursion is ok.
+            if selcx.tcx().trait_has_default_impl(data.def_id()) {
+                debug!("process_predicate: trait has default impl");
+                for bt_obligation in backtrace {
+                    debug!("process_predicate: bt_obligation = {:?}", bt_obligation.obligation);
+                    if bt_obligation.obligation.predicate == obligation.predicate {
+                        debug!("process_predicate: found a match!");
+                        return Ok(Some(vec![]));
+                    }
+                }
+            }
+
             let trait_obligation = obligation.with(data.clone());
             match selcx.select(&trait_obligation) {
                 Ok(Some(vtable)) => {