Skip to content

AFIT: incorrect "method not compatible with trait" #103457

Closed

Description

@Dirbaio

playground

pub trait SpiDevice {
    async fn transaction<'a, F: 'a>(&'a mut self, f: F);
}

impl SpiDevice for () {
    async fn transaction<'a, F: 'a>(&'a mut self, f: F) {}
}

gives the following error:

error[[E0308]](https://doc.rust-lang.org/nightly/error-index.html#E0308): method not compatible with trait
 --> src/lib.rs:9:5
  |
9 |     async fn transaction<'a, F: 'a>(&'a mut self, f: F) {}
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch
  |
note: while checking the return type of the `async fn`
 --> src/lib.rs:9:57
  |
9 |     async fn transaction<'a, F: 'a>(&'a mut self, f: F) {}
  |                                                         ^ checked the `Output` of this `async fn`, expected opaque type
note: while checking the return type of the `async fn`
 --> src/lib.rs:9:57
  |
9 |     async fn transaction<'a, F: 'a>(&'a mut self, f: F) {}
  |                                                         ^ checked the `Output` of this `async fn`, found opaque type
  = note: expected fn pointer `fn(&'a mut (), _) -> impl Future<Output = ()>`
             found fn pointer `fn(&'a mut (), _) -> impl Future<Output = ()>`
note: the lifetime `'a` as defined here...
 --> src/lib.rs:9:26
  |
9 |     async fn transaction<'a, F: 'a>(&'a mut self, f: F) {}
  |                          ^^
  = note: ...does not necessarily outlive the static lifetime

The equivalent without async works.

Activity

  1. added
    C-bugCategory: This is a bug.
    requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.
    on Oct 24, 2022
  2. compiler-errors commented on Oct 24, 2022

    @compiler-errors
    Contributor

    I've got a root cause identified for this, but still working out some weird lifetime issues that fall out after the fix.

  3. added 2 commits that reference this issue on Oct 28, 2022
  4. oli-obk commented on Nov 30, 2022

    @oli-obk
    Contributor

    This was fixed by #103491

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

C-bugCategory: This is a bug.F-async_fn_in_traitStatic async fn in traitsrequires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions