Different error messages between async and regular functions #63277
Labels
A-async-await
Area: Async & Await
A-diagnostics
Area: Messages for errors, warnings, and lints
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Hi,
Let's consider following code:
There's an error in the penultimate line - it should say
Ok(())
and Rust correctly helps to spot the mistake:The situation changes a bit when we switch to async functions:
The error message now says
the '?' operator can only be used in a function that returns 'Result' or 'Option'
, which is totally unhelpful, since the function is (or at least should be) returning aResult
, according to its signature.It seems that, when dispatching error messages, the actual return types have precedence over signatures in async functions, but it's exactly the other way around in regular functions, which leads to kinda unexpected and confusing error messages.
The text was updated successfully, but these errors were encountered: