Warning
This post was published 59 days ago. The information described in this article may have changed.
Consider this example:
fn call<'a:'static, F>(f: F)
where
F: Fn(&'a str),
{
call2(f);
}
fn call2<F>(_: F)
where
F: Fn(&'static str),
{
}
fn main() {}
This code can be compiled. The result seems to imply that if F
satisfies Fn(&'a T)
, it will also satisfy Fn(&'b T)
if 'a:'b
. This seems to not only apply to Fn
Trait but also for customized traits, for example:
trait MyTrait<'a> {}
impl<'a> MyTrait<'a> for i32 {}
fn call<'a:'static, F>(f: F)
where
F: MyTrait<'a>,
{
call2(f);
}
fn call2<F>(_: F)
where
F: MyTrait<'static>,
{
}
fn main() {}
I don't find any document that tells this point.
2 posts - 2 participants
🏷️ rust_feed