Description
The suggestion in the following code isn't great:
error[E0308]: mismatched types
--> src/main.rs:72:5
|
72 | / while let Some(i) = x.try_next().await? {
73 | | println!("{:?}", i);
74 | | }
| |_____^ expected enum `Option`, found `()`
|
= note: expected enum `Option<()>`
found unit type `()`
help: try using a variant of the expected enum
|
72 ~ Some(while let Some(i) = x.try_next().await? {
73 + println!("{:?}", i);
74 + })
|
It makes sense why it happens: the while let
expression resolves to type ()
, it's the tail expression of an async fn
that returns Option<()>
, so wrapping the expression in Some(())
would make the type checker happy, but suggesting that seems almost always wrong? I think I would prefer it if we special cased this and didn't gave a suggestion for Result<(), _>
or Option<()>
.
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: Suggestions generated by the compiler applied by `cargo fix`Diagnostics: A structured suggestion resulting in incorrect code.Diagnostics: An error or lint that needs small tweaks.Low priorityRelevant to the compiler team, which will review and decide on the PR/issue.