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

impl_trait_projections incorrectly triggers on async inherent method #110156

Closed
compiler-errors opened this issue Apr 10, 2023 · 1 comment
Closed
Labels
A-async-await Area: Async & Await AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@compiler-errors
Copy link
Member

compiler-errors commented Apr 10, 2023

I tried this code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=e7e126b11bc02ef4c8bc28e0d85e0cf0

struct Foo {}

trait IntoBar<'a> {
    type Bar: 'static;
}

impl Foo {
    async fn stuff<'a, T>(&self, into_bar: T) -> T::Bar
    where
        T: IntoBar<'a>,
    {
        todo!();
    }
}

I expected to see the code compile.

Instead, this happened:

error[[E0658]](https://doc.rust-lang.org/stable/error_codes/E0658.html): `async fn` return type cannot contain a projection or `Self` that references lifetimes from a parent scope
 --> src/lib.rs:8:50
  |
8 |     async fn stuff<'a, T>(&self, into_bar: T) -> T::Bar
  |                                                  ^^^^^^
  |
  = note: [see issue #103532 <https://github.com/rust-lang/rust/issues/103532>](https://github.com/rust-lang/rust/issues/103532) for more information

For more information about this error, try `rustc --explain E0658`.

Fails on nightly (apr 10), beta (1.69), stable (1.68).


Curiously, this code doesn't fail:

struct Foo {}

trait IntoBar<'a> {
    type Bar: 'static;
}

impl Foo {
    async fn stuff<'a, T>(&self, into_bar: T) -> <T as IntoBar<'a>>::Bar
    where
        T: IntoBar<'a>,
    {
        todo!();
    }
}

... nor does changing the return type to <T as IntoBar<'_>>::Bar...

@compiler-errors compiler-errors added the C-bug Category: This is a bug. label Apr 10, 2023
@jyn514 jyn514 added A-async-await Area: Async & Await T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 27, 2023
@eholk eholk added the AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. label May 8, 2023
@vincenzopalazzo vincenzopalazzo moved this to On deck in wg-async work May 8, 2023
@compiler-errors
Copy link
Member Author

impl_trait_projections is stabilized :>

@github-project-automation github-project-automation bot moved this from On deck to Done in wg-async work Oct 18, 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 AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
Status: Done
Development

No branches or pull requests

3 participants