Skip to content

AFIT: "method not compatible with trait" with impl for &mut T #103850

@Dirbaio

Description

@Dirbaio
Contributor

playground

pub trait Foo {
    async fn foo(&mut self);
}

impl<T: Foo> Foo for &mut T {
    async fn foo(&mut self) {}
}

gives

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 foo(&mut self) {}
  |     ^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch
  |
note: while checking the return type of the `async fn`
 --> src/lib.rs:9:29
  |
9 |     async fn foo(&mut self) {}
  |                             ^ checked the `Output` of this `async fn`, expected opaque type
note: while checking the return type of the `async fn`
 --> src/lib.rs:9:29
  |
9 |     async fn foo(&mut self) {}
  |                             ^ checked the `Output` of this `async fn`, found opaque type
  = note: expected fn pointer `fn(&mut &mut T) -> impl Future<Output = ()>`
             found fn pointer `fn(&mut &mut T) -> impl Future<Output = ()>`
note: the anonymous lifetime as defined here...
 --> src/lib.rs:8:22
  |
8 | impl<T: Foo> Foo for &mut T {
  |                      ^
  = note: ...does not necessarily outlive the static lifetime

Build using the Nightly version: 1.67.0-nightly (2022-10-31 95a3a72)
@rustbot label F-async_fn_in_traits C-bug requires-nightly

Activity

added
C-bugCategory: This is a bug.
requires-nightlyThis issue requires a nightly compiler in some way.
on Nov 1, 2022
Dirbaio

Dirbaio commented on Nov 1, 2022

@Dirbaio
ContributorAuthor

searched nightlies: from nightly-2022-10-22 to nightly-2022-11-01
regressed nightly: nightly-2022-10-29
searched commit range: 0da281b...9565dfe
regressed commit: 898f463'

likely #103608

Dirbaio

Dirbaio commented on Nov 1, 2022

@Dirbaio
ContributorAuthor

Another repro which I believe is the same bug:

pub trait Foo {
    async fn foo(&mut self);
}

struct MyFoo<'a>(&'a mut ());

impl<'a> Foo for MyFoo<'a> {
    async fn foo(&mut self) {}
}
added 4 commits that reference this issue on Nov 17, 2022
be00a0e
65bd668
d5d8eee
1521795
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.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Participants

    @Dirbaio@compiler-errors@rustbot

    Issue actions

      AFIT: "method not compatible with trait" with `impl for &mut T` · Issue #103850 · rust-lang/rust