Skip to content

type inference fails when using async_fn_in_trait #108362

Open
@LastExceed

Description

@LastExceed
#![feature(async_fn_in_trait)]

fn main() {}

trait MyTrait<T> {
	async fn foo(&mut self) -> T;
}


impl<T> MyTrait<bool> for T {
	async fn foo(&mut self) -> bool {
		true
	}
}

impl<T> MyTrait<i32> for T {
	async fn foo(&mut self) -> i32 {
		let x: bool = self.foo().await; //error[E0698]: type inside `async fn` body must be known in this context

		42
	}
}

works fine when removing async or using the async-trait crate

workaround:

let x: bool = MyTrait::<bool>::foo(self).await;

Metadata

Metadata

Labels

A-async-awaitArea: Async & AwaitA-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-inferenceArea: Type inferenceAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.WG-asyncWorking group: Async & await

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions