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: incorrect "method not compatible with trait" #103457

Closed
Dirbaio opened this issue Oct 24, 2022 · 2 comments
Closed

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

Dirbaio opened this issue Oct 24, 2022 · 2 comments
Assignees
Labels
C-bug Category: This is a bug. F-async_fn_in_trait Static async fn in traits requires-nightly This issue requires a nightly compiler in some way.

Comments

@Dirbaio
Copy link
Contributor

Dirbaio commented Oct 24, 2022

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.

@compiler-errors compiler-errors self-assigned this Oct 24, 2022
@compiler-errors compiler-errors added F-async_fn_in_trait Static async fn in traits C-bug Category: This is a bug. requires-nightly This issue requires a nightly compiler in some way. labels Oct 24, 2022
@compiler-errors
Copy link
Member

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

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 28, 2022
…=cjgillot

Remap early bound lifetimes in return-position `impl Trait` in traits too

Fixes part of rust-lang#103457

r? `@cjgillot,` though feel free to reassign, just thought you'd have sufficient context to review.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 28, 2022
…=cjgillot

Remap early bound lifetimes in return-position `impl Trait` in traits too

Fixes part of rust-lang#103457

r? ``@cjgillot,`` though feel free to reassign, just thought you'd have sufficient context to review.
@oli-obk
Copy link
Contributor

oli-obk commented Nov 30, 2022

This was fixed by #103491

@oli-obk oli-obk closed this as completed Nov 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-async_fn_in_trait Static async fn in traits requires-nightly This issue requires a nightly compiler in some way.
Projects
None yet
Development

No branches or pull requests

3 participants