-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsAsyncAwait-PolishAsync-await issues that are part of the "polish" areaAsync-await issues that are part of the "polish" areaAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.Async-await issues that have been triaged during a working group meeting.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=d8b89e2ba445cca680d18063b9d62a20
async fn f() -> Result<u8, u16> {
let x = false;
if x {
Ok(0u8)
}
Err(2u16)
}
The current output is:
Compiling playground v0.0.1 (/playground)
error[E0308]: mismatched types
--> src/lib.rs:4:9
|
3 | / if x {
4 | | Ok(0u8)
| | ^^^^^^^ expected `()`, found enum `Result`
5 | | }
| |_____- expected this to be `()`
|
= note: expected unit type `()`
found enum `Result<u8, _>`
For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` due to previous error
Ideally the output should look like it does for the non-async version:
Compiling playground v0.0.1 (/playground)
error[E0308]: mismatched types
--> src/lib.rs:4:9
|
3 | / if x {
4 | | Ok(0u8)
| | ^^^^^^^ expected `()`, found enum `Result`
5 | | }
| |_____- expected this to be `()`
|
= note: expected unit type `()`
found enum `Result<u8, _>`
help: you might have meant to return this value
|
4 | return Ok(0u8);
| ++++++ +
For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` due to previous error
Metadata
Metadata
Assignees
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsAsyncAwait-PolishAsync-await issues that are part of the "polish" areaAsync-await issues that are part of the "polish" areaAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.Async-await issues that have been triaged during a working group meeting.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.