-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitAsyncAwait-PolishAsync-await issues that are part of the "polish" areaAsync-await issues that are part of the "polish" areaT-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.
Description
The following code (playground) fails to compile:
#![feature(futures_api, async_await, await_macro)]
struct Xyz {
a: u64,
}
trait Foo {}
impl Xyz {
async fn do_sth<'a>(
&'a self, foo: &'a dyn Foo
) -> bool
{
true
}
}
Error:
error[E0709]: multiple different lifetimes used in arguments of `async fn`
--> src/lib.rs:11:10
|
11 | &'a self, foo: &'a dyn Foo
| ^^ ^^^^^^^ different lifetime here
| |
| first lifetime here
|
= help: `async fn` can only accept borrowed values with identical lifetimes
This is very surprising, since only one lifetime is visible.
Workaround (thanks to @Nemo157 ):
Defining the function as
async fn do_sth<'a>(&'a self, foo: &'a (dyn Foo + 'a)) -> bool
will allow compilation.
Metadata
Metadata
Assignees
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitAsyncAwait-PolishAsync-await issues that are part of the "polish" areaAsync-await issues that are part of the "polish" areaT-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.