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 no longer seems to play nice with lifetime GATs #113796

Closed
yoshuawuyts opened this issue Jul 17, 2023 · 4 comments · Fixed by #113704
Closed

AFIT no longer seems to play nice with lifetime GATs #113796

yoshuawuyts opened this issue Jul 17, 2023 · 4 comments · Fixed by #113704
Assignees
Labels
A-async-await Area: Async & Await A-implied-bounds Area: Related to implied bounds A-lifetimes Area: lifetime related 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

@yoshuawuyts
Copy link
Member

Tracking issue: #91611

A few months ago I authored a complete example for a possible AsyncIterator::lend method. This used to compile fine on rustc 1.71.0-nightly (f5559e338 2023-04-24), but it no longer does on the latest nightly. Here is a minimized repro:

#![allow(incomplete_features)]
#![feature(async_fn_in_trait)]

trait AsyncLendingIterator {
    type Item<'a>
    where
        Self: 'a;

    async fn next(&mut self) -> Option<Self::Item<'_>>;
}

struct Lend<I>(I);
impl<I> AsyncLendingIterator for Lend<I> {
    type Item<'a> = &'a I
    where
        Self: 'a;

    async fn next(&mut self) -> Option<Self::Item<'_>> {
        todo!()
    }
}

This gives the following error:

Compiling playground v0.0.1 (/playground)
error[[E0311]](https://doc.rust-lang.org/nightly/error_codes/E0311.html): the parameter type `T` may not live long enough
  --> src/main.rs:29:5
   |
29 |     async fn next(&mut self) -> Option<Self::Item<'_>> {
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: the parameter type `T` must be valid for the anonymous lifetime as defined here...
  --> src/main.rs:9:19
   |
9  |     async fn next(&mut self) -> Option<Self::Item<'_>>;
   |                   ^
note: ...so that the type `LendingIter<T>` will meet its required lifetime bounds
  --> src/main.rs:29:5
   |
29 |     async fn next(&mut self) -> Option<Self::Item<'_>> {
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0311`.
error: could not compile `playground` (bin "playground") due to previous error

I have a feeling async traits no longer play nice with lifetime GATs?

Meta

Tested on the playground using the current nightly:

nightly-2023-07-16 0e8e857b11f60a785aea

cc/ @rust-lang/wg-async, @compiler-errors

@yoshuawuyts yoshuawuyts added the C-bug Category: This is a bug. label Jul 17, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 17, 2023
@compiler-errors compiler-errors added A-lifetimes Area: lifetime related requires-nightly This issue requires a nightly compiler in some way. F-async_fn_in_trait Static async fn in traits A-implied-bounds Area: Related to implied bounds and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jul 17, 2023
@compiler-errors compiler-errors self-assigned this Jul 17, 2023
@compiler-errors
Copy link
Member

I'll at least bisect this, and check if it's fixed by #113704.

@lqd
Copy link
Member

lqd commented Jul 17, 2023

@compiler-errors
Copy link
Member

it should be fixed by a slight modification of #113704 though.

@lqd
Copy link
Member

lqd commented Jul 17, 2023

Great! (I just tested the PR as-is)

@yoshuawuyts yoshuawuyts changed the title AFIT no longer seems to place nice with lifetime GATs AFIT no longer seems to play nice with lifetime GATs Jul 18, 2023
@bors bors closed this as completed in b969b83 Jul 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await Area: Async & Await A-implied-bounds Area: Related to implied bounds A-lifetimes Area: lifetime related 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
Development

Successfully merging a pull request may close this issue.

5 participants