Why does compiler allow me to define function fn print<P: Tr> (...);
in some trait and then implement that trait as follows: fn print<P: Tr + 'static> (...) {}
?
I thought Tr + 'static
where Tr is some other trait is stronger requirement for a type than just Tr
. So why does it happen?
Playground URL: Rust Playground
use std::fmt::Display;
trait Printer {
fn print<P: Display>(&self, printable: P);
}
struct TestObj;
impl Printer for TestObj {
fn print<P: Display + 'static>(&self, printable: P) {}
}
fn main() {}
this can cause a use after free in safe code, seems to be a bug
https://github.com/rust-lang/rust/issues/18937
1 Like