fn test<'a>()
where
'a: 'a, // <- makes sure `'a` is early-bound; late-bound lifetimes are already rejected
{
let f = |_: &'a str| {};
f(&String::new());
}
compiles on 1.63 but will stop compiling in 1.64 with the following error because of #98835 (comment) (#100544):
error[E0716]: temporary value dropped while borrowed
--> src/lib.rs:6:8
|
1 | fn test<'a>()
| -- lifetime `'a` defined here
...
6 | f(&String::new());
| ---^^^^^^^^^^^^^-- temporary value is freed at the end of this statement
| | |
| | creates a temporary which is freed while still in use
| argument requires that borrow lasts for `'a`
We should detect cases of lifetime errors caused by closures using a lifetime of its enclosing item and suggest using an anonymous lifetime when appropriate to make the code compile.
compiles on 1.63 but will stop compiling in 1.64 with the following error because of #98835 (comment) (#100544):
We should detect cases of lifetime errors caused by closures using a lifetime of its enclosing item and suggest using an anonymous lifetime when appropriate to make the code compile.