use std::marker::PhantomData;
struct A<'a,'b>(PhantomData<&'a ()>,PhantomData<&'b ()>);
fn test<F>(f:F)
where F: for<'a,'b> FnOnce(&'a A<'a,'b>){}
fn func1<'a>(v:&'a A<'a,'a>){
}
fn main(){
test(func1);
}
In this example, the compiler says:
implementation of `FnOnce` is not general enough
`for<'a> fn(&'a A<'a, 'a>) {func1}` must implement `FnOnce<(&'0 A<'0, '1>,)>`, for any two lifetimes `'0` and `'1`...
...but it actually implements `FnOnce<(&'2 A<'2, '2>,)>`, for some specific lifetime `'2`
According to placeholder leak
Does func1: for<'a,'b> FnOnce(&'a A<'a,'b>)
, the document says that replace 'a
and 'b
to '0
and '1
, that is FnOnce(&'0 A<'0,'1>)
, and associate the trait with the implementation, assuming the implementation would be something like this:
impl<'a> FnOnce<&'a A<'a,'a>> for func1{/*...*/}
then we can get '0 == '$a
and '1 == '$a
, hence, the taint set for '0
is {'0, '$a}
, and the taint set for '1
is {'1, '$a}
, the match should success, why does the compiler say the implementation is not general enough? Is there something about "leak" I misunderstood?