Skip to content

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

Closed
@Dirbaio

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.

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.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions