Why does this rust code compile?
use std::fmt::Display;
fn g<T: 'static + Display>(t: T) {
println!("{}", t);
}
fn t() {
let x: i32 = 12;
g(x);
}
fn main() {
t();
}
Certainly in the function t()
the local variable x
is not static, yet the template specification of g
seems to the demand that it must be. What am I misunderstanding?
For context: the example above is clearly very contrived. In a more complicated setting that I am working on, the compiler is forcing me to use T: 'static
instead of just T
, but I don't want to use it just for static types. To my surprise however it just also works for non static variables and I am confused...