Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
b-naber committed Nov 12, 2021
1 parent 26ca71f commit 7a4aa65
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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() {}
Original file line number Diff line number Diff line change
@@ -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() {}

0 comments on commit 7a4aa65

Please sign in to comment.