Closed
Description
For the following code (Playground link):
fn foo<'a>(u: &'a usize) -> impl IntoIterator<Item = usize> + 'a {
std::thread::spawn(move || {
println!("{}", u);
});
vec![]
}
rustc
provides the following error and suggestion:
error: cannot infer an appropriate lifetime
--> src/lib.rs:2:24
|
2 | std::thread::spawn(move || {
| _____------------------_^
| | |
| | this return type evaluates to the `'static` lifetime...
3 | | println!("{}", u);
4 | | });
| |_____^ ...but this borrow...
|
note: ...can't outlive the lifetime 'a as defined on the function body at 1:8
--> src/lib.rs:1:8
|
1 | fn foo<'a>(u: &'a usize) -> impl IntoIterator<Item = usize> + 'a {
| ^^
help: you can add a constraint to the return type to make it last less than `'static` and match the lifetime 'a as defined on the function body at 1:8
|
2 | std::thread::spawn + 'a(move || {
| ^^^^^^^^^^^^^^^^^^^^^^^
But applying this suggestion results in a syntax error:
error: expected `:`, found `(`
--> src/lib.rs:2:28
|
2 | std::thread::spawn + 'a(move || {
| ^ expected `:`
Using the Playground link, I reproduced this invalid suggestion on Rust 1.37.0 stable, 1.38.0-beta.2, and 1.39.0-nightly 2019-08-23.