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<()>.
The suggestion in the following code isn't great:
It makes sense why it happens: the
while letexpression resolves to type(), it's the tail expression of anasync fnthat returnsOption<()>, so wrapping the expression inSome(())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 forResult<(), _>orOption<()>.