Cannot infer an appropriate lifetime for a closure that returns a reference
问题 Considering the following code: fn foo<'a, T: 'a>(t: T) -> Box<Fn() -> &'a T + 'a> { Box::new(move || &t) } What I expect: The type T has lifetime 'a . The value t live as long as T . t moves to the closure, so the closure live as long as t The closure returns a reference to t which was moved to the closure. So the reference is valid as long as the closure exists. There is no lifetime problem, the code compiles. What actually happens: The code does not compile: error[E0495]: cannot infer an