Closed
Description
Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=b539ebe10f181c1f2b245a021684dff1
use std::future::Future;
async fn foo() -> Result<(), i32> {
func(async { Ok::<_, i32>(()) })?;
Ok(())
}
async fn func<T>(fut: impl Future<Output = T>) -> T {
fut.await
}
The current output is:
Compiling playground v0.0.1 (/playground)
error[[E0277]](https://doc.rust-lang.org/stable/error-index.html#E0277): the `?` operator can only be applied to values that implement `Try`
--> src/lib.rs:4:5
|
4 | func(async { Ok::<_, i32>(()) })?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the `?` operator cannot be applied to type `impl Future<Output = Result<(), i32>>`
|
= help: the trait `Try` is not implemented for `impl Future<Output = Result<(), i32>>`
For more information about this error, try `rustc --explain E0277`.
Ideally the output should look like:
Compiling playground v0.0.1 (/playground)
error[[E0277]](https://doc.rust-lang.org/stable/error-index.html#E0277): the `?` operator can only be applied to values that implement `Try`
--> src/lib.rs:4:5
|
4 | func(async { Ok::<_, i32>(()) })?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the `?` operator cannot be applied to type `impl Future<Output = Result<(), i32>>`
|
= help: try adding `.await` or something
--> src/lib.rs:4:5
|
4 | func(async { Ok::<_, i32>(()) }).await?;
| ++++++
|
For more information about this error, try `rustc --explain E0277`.