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: "method not compatible with trait" with impl for &mut T #103850

Closed
Dirbaio opened this issue Nov 1, 2022 · 2 comments · Fixed by #103852
Closed

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

Dirbaio opened this issue Nov 1, 2022 · 2 comments · Fixed by #103852
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 Nov 1, 2022

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

@rustbot rustbot added 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. labels Nov 1, 2022
@compiler-errors compiler-errors self-assigned this Nov 1, 2022
@Dirbaio
Copy link
Contributor Author

Dirbaio commented Nov 1, 2022

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
Copy link
Contributor Author

Dirbaio commented Nov 1, 2022

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) {}
}

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 17, 2022
…impl, r=lcnr

Don't remap early-bound regions for return-position `impl Trait` in trait originating from `impl`

long title 😓

We don't want to remap early-bound regions that originate from the `impl`s themselves, since they have no corresponding region in the trait. Not sure if there's a better condition than checking if the EBR's def-id's parent is the impl -- maybe we should be checking if the region comes from the method or RPITIT... 🤷

r? types

Fixes rust-lang#103850
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 17, 2022
…impl, r=lcnr

Don't remap early-bound regions for return-position `impl Trait` in trait originating from `impl`

long title 😓

We don't want to remap early-bound regions that originate from the `impl`s themselves, since they have no corresponding region in the trait. Not sure if there's a better condition than checking if the EBR's def-id's parent is the impl -- maybe we should be checking if the region comes from the method or RPITIT... 🤷

r? types

Fixes rust-lang#103850
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 17, 2022
…impl, r=lcnr

Don't remap early-bound regions for return-position `impl Trait` in trait originating from `impl`

long title 😓

We don't want to remap early-bound regions that originate from the `impl`s themselves, since they have no corresponding region in the trait. Not sure if there's a better condition than checking if the EBR's def-id's parent is the impl -- maybe we should be checking if the region comes from the method or RPITIT... 🤷

r? types

Fixes rust-lang#103850
@bors bors closed this as completed in 1521795 Nov 18, 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
3 participants