Making trait method `async` causes inference failure (E0790)
Open
Nobody has claimed this yet.
A-async-await
A-inference
C-bug
T-compiler
T-types
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the example from src/main.rs in the linked Rust Playground, then compare it with the linked synchronous version. Start with the E0790 diagnostic and related issue #135698; done means the async form compiles with the inferred Frobbable type as the synchronous form does.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100