The following doesn't compile, as it tries to assign U a concrete &'x i32 instead of &'a i32:
trait Unary<T> {}
impl<T, U, F: Fn(T) -> U> Unary<T> for F {}
fn unary<F: for<'a> Unary<&'a T>, T>() {}
fn test<F: for<'a> Fn(&'a i32) -> &'a i32>() {
unary::<F, i32>()
}
Removing the U type parameter makes it work - U is only used for the associated type Fn::Output anyway:
#![feature(unboxed_closures)]
trait Unary<T> {}
impl<T, F: Fn<(T,)>> Unary<T> for F {}
fn unary<F: for<'a> Unary<&'a T>, T>() {}
fn test<F: for<'a> Fn(&'a i32) -> &'a i32>() {
unary::<F, i32>()
}
AFAICT, the selection results in for<'a, U> F: Fn<(&'a i32,), Output=U> in the first case, and for<'a> F: Fn<(&'a i32,)> in the second case, and we refuse to allow U to be parameterized by 'a in the former case, even though it's only used to satisfy the sugary form of the Fn trait.
The following doesn't compile, as it tries to assign
Ua concrete&'x i32instead of&'a i32:Removing the
Utype parameter makes it work -Uis only used for the associated typeFn::Outputanyway:AFAICT, the selection results in
for<'a, U> F: Fn<(&'a i32,), Output=U>in the first case, andfor<'a> F: Fn<(&'a i32,)>in the second case, and we refuse to allowUto be parameterized by'ain the former case, even though it's only used to satisfy the sugary form of theFntrait.