Weird lifetime error with closure and early-bound lifetime
struct S; impl S { fn f<'a:'a>(_x:&'a i32) {} } fn main() { let g1: &Fn(&i32) = &|x| S::f(x); g1(&1); let g2 = &|x| S::f(x); g2(&1); }
<anon>:9:9: 9:10 error: borrowed value does not live long enough
<anon>:9 g2(&1);
^
<anon>:8:27: 10:2 note: reference must be valid for the block suffix following statement 2 at 8:26...
<anon>: 8 let g2 = &|x| S::f(x);
<anon>: 9 g2(&1);
<anon>:10 }
<anon>:9:5: 9:12 note: ...but borrowed value is only valid for the statement at 9:4
<anon>:9 g2(&1);
^~~~~~~
<anon>:9:5: 9:12 help: consider using a `let` binding to increase its lifetime
<anon>:9 g2(&1);
^~~~~~~
error: aborting due to previous error
Lifetime inference is doing something weird with the second closure.