With the code
fn foo<'a, 'b>(
state: &'b mut i32,
) -> impl FnMut(&'a str) -> &'static str + 'b {
|s| "hi"
}
I get an error
error[E0482]: lifetime of return value does not outlive the function call
112 | ) -> impl FnMut(&'a str) -> &'static str + 'b {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: the return value is only valid for the lifetime `'a` as defined on the function body at 110:9
110 | fn foo1<'a, 'b>(
| ^^
But somehow the code
fn foo2<'a, 'b>(
state: &'b mut Option<&'a i32>,
) -> impl FnMut(&'a str) -> &'static str + 'b {
|s| "hi"
}
compiles without errors. Why does the type of state change the lifetime of the closure?