Open
Description
The old solver eagerly detects unbounded recursion and forces the affected goals to be ambiguous. This check forces some goals which would not recurse to ambiguity as well. These goals now correctly result in NoSolution
.
This test fails with ambiguity with old solver due to multiple candidates, and successfully compiles with new:
trait Trait<T, DUMMY> {}
struct W<T>(T);
// To pass coherence.
trait IsNotI32 {}
// This impl does not hold but gets forced as ambiguous due to
// `fn match_fresh_trait_refs`.
impl<T, DUMMY> Trait<T, DUMMY> for W<T>
where
DUMMY: IsNotI32,
W<u32>: Trait<i32, DUMMY> {}
// This impl holds.
impl Trait<u32, i32> for W<u32> {}
fn impls_trait<T: Trait<U, DUMMY>, U, DUMMY>() {}
fn main() {
impls_trait::<W<_>, _, _>()
}
Removing this check does worsen performance by not as eagerly detecting overflow. However, correctly tracking the stack dependent behavior for this check would probably have a far greater performance impact.
This check prevents typenum from reaching the recursion limit in the old solver, cc #56