Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async/await: Usage of trait objects reports multiple different lifetimes when only one is used #58885

Open
Matthias247 opened this Issue Mar 3, 2019 · 1 comment

Comments

Projects
None yet
4 participants
@Matthias247
Copy link
Contributor

Matthias247 commented Mar 3, 2019

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.

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Mar 5, 2019

Tagging as blocking -- this issue ought to be resolved before async-await can be stabilized, because it is generally surprising and kind of a bug. However, we expect it to get fixed by fixing #56238 (see that issue for notes as to why).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.