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

Unexpected lifetime bound in async trait method #104529

Closed
fakedrake opened this issue Nov 17, 2022 · 0 comments · Fixed by #105247
Closed

Unexpected lifetime bound in async trait method #104529

fakedrake opened this issue Nov 17, 2022 · 0 comments · Fixed by #105247
Labels
F-async_fn_in_trait Static async fn in traits T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@fakedrake
Copy link

fakedrake commented Nov 17, 2022

I have this program

#![allow(incomplete_features)]
#![feature(async_fn_in_trait)]
use std::marker::PhantomData;

struct Y<'s,'e:'s>(PhantomData<(&'s (), &'e mut &'e ())>);
trait Tr<'e> {
    // Removing async works fine
    async fn f<'s>(&self, y: Y<'s, 'e>) -> Y<'s,'e>;
}

playground

That throws this strange compilation error on nightly

Compiling playground v0.0.1 (/playground)
error[[E0478]](https://doc.rust-lang.org/nightly/error-index.html#E0478): lifetime bound not satisfied
 --> src/lib.rs:8:44
  |
8 |     async fn f<'s>(&self, y: Y<'s, 'e>) -> Y<'s,'e>;
  |                                            ^^^^^^^^
  |
note: lifetime parameter instantiated with the lifetime `'e` as defined here
 --> src/lib.rs:6:10
  |
6 | trait Tr<'e> {
  |          ^^
note: but lifetime parameter must outlive the lifetime `'s` as defined here
 --> src/lib.rs:8:16
  |
8 |     async fn f<'s>(&self, y: Y<'s, 'e>) -> Y<'s,'e>;
  |                ^^

For more information about this error, try `rustc --explain E0478`.
error: could not compile `playground` due to previous error

If I remove async it works fine. Any idea why this happens?

Edit: this program compiles normally:

use std::marker::PhantomData;

struct Y<'s,'e:'s>(PhantomData<(&'s (), &'e mut &'e ())>);
struct A<'e>(PhantomData<&'e ()>);

impl<'e> A<'e> {
    async fn f<'s>(&self, y: Y<'s, 'e>) -> Y<'s,'e> {
        y
    }
}
@fakedrake fakedrake added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 17, 2022
@fakedrake fakedrake changed the title Unexpected lifetime bound in async Unexpected lifetime bound in async trait method Nov 17, 2022
@compiler-errors compiler-errors added F-async_fn_in_trait Static async fn in traits and removed A-diagnostics Area: Messages for errors, warnings, and lints labels Nov 17, 2022
@bors bors closed this as completed in d055d6a Dec 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-async_fn_in_trait Static async fn in traits T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants