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

AFIT+GAT: Self may not live long enough #104908

Closed
Dirbaio opened this issue Nov 25, 2022 · 0 comments · Fixed by #105247
Closed

AFIT+GAT: Self may not live long enough #104908

Dirbaio opened this issue Nov 25, 2022 · 0 comments · Fixed by #105247
Labels
F-async_fn_in_trait Static async fn in traits

Comments

@Dirbaio
Copy link
Contributor

Dirbaio commented Nov 25, 2022

playground

trait TcpStack {
    type Connection<'a>: Sized where Self: 'a;
    async fn connect<'a>(&'a self) -> Self::Connection<'a>;
}

fails with

error[E0309]: the parameter type `Self` may not live long enough
 --> src/lib.rs:6:39
  |
6 |     async fn connect<'a>(&'a self) -> Self::Connection<'a>;
  |                                       ^^^^^^^^^^^^^^^^^^^^
  |
  = help: consider adding an explicit lifetime bound `Self: 'a`...
  = note: ...so that the type `Self` will meet its required lifetime bounds...
note: ...that is required by this bound
 --> src/lib.rs:5:44
  |
5 |     type Connection<'a>: Sized where Self: 'a;
  |                                            ^^

However, in the method context, Self: 'a is already implied by having a &'a self argument. The equivalent without async builds fine thanks to that, I think the async one should too.

@rustbot label F-async_fn_in_trait

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants