-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitA-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsAsyncAwait-PolishAsync-await issues that are part of the "polish" areaAsync-await issues that are part of the "polish" areaC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
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.
Metadata
Metadata
Assignees
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitA-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsAsyncAwait-PolishAsync-await issues that are part of the "polish" areaAsync-await issues that are part of the "polish" areaC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team