Skip to content

rustc doesn't suggest missing .await before a ? #71811

@jimblandy

Description

@jimblandy

When I compile the following code:

async fn fallible() -> Result<(), ()> { Ok(()) } async fn caller() -> Result<(), ()> { fallible() /* mising .await */ ?; Ok(()) } fn main() -> Result<(), ()> { futures::executor::block_on(caller()) } 

rustc says:

error[E0277]: the `?` operator can only be applied to values that implement `std::ops::Try` --> src/main.rs:4:5 | 4 | fallible() /* mising .await */ ?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the `?` operator cannot be applied to type `impl core::future::future::Future` | = help: the trait `std::ops::Try` is not implemented for `impl core::future::future::Future` = note: required by `std::ops::Try::into_result` 

I think it should notice that the program is trying to apply ? to a future, and suggest awaiting it.

(If there is an existing issue for this, it is not labeled A-async-await and A-suggestion-diagnostics.)

Metadata

Metadata

Assignees

Labels

A-async-awaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.C-enhancementCategory: An issue proposing an enhancement or a PR with one.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