Skip to content

Commit dccc8db

Browse files
committed
coinductive cycle leak check test
1 parent 5119f7d commit dccc8db

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// check-pass
2+
// compile-flags: -Ztrait-solver=next
3+
#![feature(rustc_attrs)]
4+
5+
#[rustc_coinductive]
6+
trait Trait<T> {}
7+
impl<'a, 'b, T> Trait<T> for (&'a (), &'b ())
8+
where
9+
'b: 'a,
10+
&'a (): Trait<T>,
11+
{}
12+
13+
impl Trait<i32> for &'static () {}
14+
impl<'a> Trait<u32> for &'a ()
15+
where
16+
for<'b> (&'a (), &'b ()): Trait<u32>,
17+
{}
18+
19+
20+
fn impls_trait<T: Trait<U>, U>() {}
21+
22+
fn main() {
23+
// This infers to `impls_trait::<(&'static (), &'static ()), i32>();`
24+
//
25+
// In the first attempt we have 2 candidates for `&'a (): Trait<_>`
26+
// and we get ambiguity. The result is therefore ambiguity with a `'b: 'a`
27+
// constraint. The next attempt then uses that provisional result when
28+
// trying to apply `impl<'a> Trait<u32> for &'a ()`. This means we get a
29+
// `for<'b> 'b: 'a` bound which fails the leak check. Because of this we
30+
// end up with a single impl for `&'a (): Trait<_>` which infers `_` to `i32`
31+
// and succeeds.
32+
impls_trait::<(&(), &()), _>();
33+
}

0 commit comments

Comments
 (0)