Where does the document say that the satisfaction relationship is transitive between two trait bounds?
⚓ Rust 📅 2025-05-06 👤 surdeus 👁️ 13Consider 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