Skip to content

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

Closed
@Dirbaio

Description

@Dirbaio

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions