Closed
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.