Skip to content

impl_trait_projections incorrectly triggers on async inherent method #110156

@compiler-errors

Description

@compiler-errors

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...

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-async-awaitArea: Async & AwaitAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions