Why can I not return a mutable reference to an outer variable from a closure?
问题 I was playing around with Rust closures when I hit this interesting scenario: fn main() { let mut y = 10; let f = || &mut y; f(); } This gives an error: error[E0495]: cannot infer an appropriate lifetime for borrow expression due to conflicting requirements --> src/main.rs:4:16 | 4 | let f = || &mut y; | ^^^^^^ | note: first, the lifetime cannot outlive the lifetime as defined on the body at 4:13... --> src/main.rs:4:13 | 4 | let f = || &mut y; | ^^^^^^^^^ note: ...so that closure can access