If you create a function returning an impl Trait
which requires a lifetime that can't be elided, rustc tells you to add it.
use futures::prelude::*;
fn make_fut(input: &()) -> impl Future<Output = ()> {
async move {
return *input
}
}
error[E0700]: hidden type for `impl futures::Future<Output = ()>` captures lifetime that does not appear in bounds
--> src/lib.rs:4:5
|
3 | fn make_fut(input: &()) -> impl Future<Output = ()> {
| --- ------------------------ opaque type defined here
| |
| hidden type `{async block@src/lib.rs:4:5: 4:15}` captures the anonymous lifetime defined here
4 | / async move {
5 | | return *input
6 | | }
| |_____^
|
help: add a `use<...>` bound to explicitly capture `'_`
|
3 | fn make_fut(input: &()) -> impl Future<Output = ()> + use<'_> {
| +++++++++
For more information about this error, try `rustc --explain E0700`.
This error can be fixed by simply adding + '_
to the return type, but rustc tells use to add + use<'_>
instead. Running rustc --explain E0700
only shows the former change and doesn't mention use<'_>
at all. The Rust book contains no mention of use
being used in this context.
What is this use<'lifetime>
syntax? Where is it documented and how can I learn about when I should use it over another syntax?
rustc --explain
mentioning the old way is a bug you should report. – Dandle