3 // This test checks that we're correctly dealing with inductive cycles
4 // with canonical inference variables.
9 impl IsNotU32 for i32 {}
10 impl<T: IsNotU32, U> Trait<T, U> for () // impl 1
15 impl<T> Trait<u32, T> for () {} // impl 2
17 // If we now check whether `(): Trait<?0, ?1>` holds this has to
18 // result in ambiguity as both `for<T> (): Trait<u32, T>` and `(): Trait<i32, u32>`
19 // applies. The remainder of this test asserts that.
21 // If we were to error on inductive cycles with canonical inference variables
22 // this would be wrong:
26 // - ?0: IsNotU32 // ambig
27 // - (): Trait<?1, ?0> // canonical cycle -> err
32 // Result: OK ?0 == u32.
34 // (): Trait<i32, u32>
36 // - i32: IsNotU32 // ok
37 // - (): Trait<u32, i32>
39 // - u32: IsNotU32 // err
44 // - impl 2 (trivial ERR)
48 // This would mean that `(): Trait<?0, ?1>` is not complete,
49 // which is unsound if we're in coherence.
51 fn implements_trait<T, U>() -> (T, U)
58 // A hack to only constrain the infer vars after first checking
59 // the `(): Trait<_, _>`.
61 impl<T> Constrain<T> for T {}
62 fn constrain<T: Constrain<U>, U>(_: U) {}
65 let (x, y) = implements_trait::<_, _>();
67 constrain::<i32, _>(x);
68 constrain::<u32, _>(y);