blob: e4c954eeb33d2bd3fa98af002c1e3366781bc6ba (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
//check-pass
use higher_kinded_types::*;
mod higher_kinded_types {
pub(crate) trait HKT {
type Of<'lt>;
}
pub(crate) trait WithLifetime<'lt> {
type T;
}
impl<T: ?Sized + for<'any> WithLifetime<'any>> HKT for T {
type Of<'lt> = <T as WithLifetime<'lt>>::T;
}
}
trait Trait {
type Gat<'lt>;
}
impl Trait for () {
type Gat<'lt> = ();
}
/// Same as `Trait`, but using HKTs rather than GATs
trait HTrait {
type Hat: ?Sized + HKT;
}
impl<T: Trait> HTrait for T {
type Hat = dyn for<'lt> WithLifetime<'lt, T = T::Gat<'lt>>;
}
impl<Hat: ?Sized + HKT> Trait for Box<dyn '_ + HTrait<Hat = Hat>> {
type Gat<'lt> = Hat::Of<'lt>;
}
fn existential() -> impl for<'a> Trait<Gat<'a> = ()> {}
fn dyn_hoops<T: Trait>(
_: T,
) -> Box<dyn HTrait<Hat = dyn for<'a> WithLifetime<'a, T = T::Gat<'a>>>> {
loop {}
}
fn main() {
let _ = || -> _ { dyn_hoops(existential()) };
}
|