Closed
Description
This code fails to compile with a very strange error:
#![feature(test, futures_api, async_await, await_macro)]
struct HasLifetime<'a>(&'a bool);
async fn bug(lifetime: HasLifetime) {
if *lifetime.0 { }
}
Error given:
error: cannot infer an appropriate lifetime
--> src/lib.rs:3:37
|
3 | async fn bug(lifetime: HasLifetime) {
| ^
| |
| _____________________________________this return type evaluates to the `'static` lifetime...
| |
4 | | if *lifetime.0 { }
5 | | }
| |_^ ...but this borrow...
|
note: ...can't outlive the anonymous lifetime #1 defined on the function body at 3:1
--> src/lib.rs:3:1
|
3 | / async fn bug(lifetime: HasLifetime) {
4 | | if *lifetime.0 { }
5 | | }
| |_^
help: you can add a constraint to the return type to make it last less than `'static` and match the anonymous lifetime #1 defined on the function body at 3:1
|
3 | async fn bug(lifetime: HasLifetime) + '_{
| ^^^^
It seems the compiler fails to generate a lifetime constraint on the impl Future<...>
the function compiles down to because there is no apparent lifetime on HasLifetime
. Replacing it with HasLifetime<'_>
fixes the problem.