fn main() { let _ref_in_ref_out = |var: &i64| var; } This does not compile:
error: lifetime may not live long enough --> src/main.rs:2:39 | 2 | let _ref_in_ref_out = |var: &i64| var; | - - ^^^ returning this value requires that `'1` must outlive `'2` | | | | | return type of closure is &'2 i64 | let's call the lifetime of this reference `'1` Apparently the compiler infers two different lifetimes (for the argument and the return type), instead of it being the same.
Is it possible to write a closure so that the input lifetime is the same as the output lifetime?
Something like
fn ref_in_ref_out<'a> (var: &'a i64) -> &'a i64 { var } but as a closure