add tests
This commit is contained in:
parent
26ca71fdb2
commit
7a4aa65810
@ -0,0 +1,43 @@
|
||||
// check-pass
|
||||
|
||||
#![feature(generic_associated_types)]
|
||||
|
||||
use std::marker::PhantomData;
|
||||
|
||||
trait Family: Sized {
|
||||
type Item<'a>;
|
||||
|
||||
fn apply_all<F>(&self, f: F)
|
||||
where
|
||||
F: FamilyItemFn<Self> { }
|
||||
}
|
||||
|
||||
struct Array<T>(PhantomData<T>);
|
||||
|
||||
impl<T: 'static> Family for Array<T> {
|
||||
type Item<'a> = &'a T;
|
||||
}
|
||||
|
||||
trait FamilyItemFn<T: Family> {
|
||||
fn apply(&self, item: T::Item<'_>);
|
||||
}
|
||||
|
||||
impl<T, F> FamilyItemFn<T> for F
|
||||
where
|
||||
T: Family,
|
||||
for<'a> F: Fn(T::Item<'a>)
|
||||
{
|
||||
fn apply(&self, item: T::Item<'_>) {
|
||||
(*self)(item);
|
||||
}
|
||||
}
|
||||
|
||||
fn process<T: 'static>(array: Array<T>) {
|
||||
// Works
|
||||
array.apply_all(|x: &T| { });
|
||||
|
||||
// ICE: NoSolution
|
||||
array.apply_all(|x: <Array<T> as Family>::Item<'_>| { });
|
||||
}
|
||||
|
||||
fn main() {}
|
@ -0,0 +1,37 @@
|
||||
//check-pass
|
||||
|
||||
#![feature(generic_associated_types)]
|
||||
|
||||
trait Yokeable<'a>: 'static {
|
||||
type Output: 'a;
|
||||
}
|
||||
|
||||
trait IsCovariant<'a> {}
|
||||
|
||||
struct Yoke<Y: for<'a> Yokeable<'a>> {
|
||||
data: Y,
|
||||
}
|
||||
|
||||
impl<Y: for<'a> Yokeable<'a>> Yoke<Y> {
|
||||
fn project<Y2: for<'a> Yokeable<'a>>(&self, _f: for<'a> fn(<Y as Yokeable<'a>>::Output, &'a ())
|
||||
-> <Y2 as Yokeable<'a>>::Output) -> Yoke<Y2> {
|
||||
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
fn _upcast<Y>(x: Yoke<Y>) -> Yoke<Box<dyn IsCovariant<'static> + 'static>> where
|
||||
Y: for<'a> Yokeable<'a>,
|
||||
for<'a> <Y as Yokeable<'a>>::Output: IsCovariant<'a>
|
||||
{
|
||||
x.project(|data, _| {
|
||||
Box::new(data)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
impl<'a> Yokeable<'a> for Box<dyn IsCovariant<'static> + 'static> {
|
||||
type Output = Box<dyn IsCovariant<'a> + 'a>;
|
||||
}
|
||||
|
||||
fn main() {}
|
Loading…
Reference in New Issue
Block a user