Skip to content

Making trait method async causes inference failure (E0790) #140987

Open
@benschulz

Description

@benschulz

I tried this code (playground):

struct Frob;

trait FromFrob: Sized {
    async fn from_frob(frob: &Frob) -> Self;
}

struct Frobbable;
impl FromFrob for Frobbable {
    async fn from_frob(_frob: &Frob) -> Self {
        todo!()
    }
}

fn main() {
    futures::executor::block_on(async move {
        let _: Frobbable = FromFrob::from_frob(&Frob).await;
    });
}

I expected to see this happen: Compilation succeeds as for the synchronous version (playground).

Instead, this happened: Compilation failed with the following error.

error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type
  --> src/main.rs:16:28
   |
4  |     async fn from_frob(frob: &Frob) -> Self;
   |     ---------------------------------------- `FromFrob::from_frob` defined here
...
16 |         let _: Frobbable = FromFrob::from_frob(&Frob).await;
   |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot call associated function of trait
   |
help: use the fully-qualified path to the only available implementation
   |
16 |         let _: Frobbable = <Frobbable as FromFrob>::from_frob(&Frob).await;
   |                            +++++++++++++         +

Meta

rustc --version --verbose:

rustc 1.89.0-nightly (414482f6a 2025-05-13)
binary: rustc
commit-hash: 414482f6a0d4e7290f614300581a0b55442552a3
commit-date: 2025-05-13
host: x86_64-unknown-linux-gnu
release: 1.89.0-nightly
LLVM version: 20.1.4

I also tried RUSTFLAGS="-Znext-solver=globally" which had no impact.

Potentially relates to #135698.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-async-awaitArea: Async & AwaitA-inferenceArea: Type inferenceC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions