You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Special case suggestion for missing tail expression when dealing with Ok(()) and Some(()) #90553
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<()>.
Activity
m-ou-se commentedon Nov 4, 2021
How about something like this?
m-ou-se commentedon Nov 4, 2021
(Just need to figure out a way to detect whether the expression was the final one in a block.)
estebank commentedon Nov 4, 2021
That looks good!
Rollup merge of rust-lang#90575 - m-ou-se:compatible-variant-improvem…
Rollup merge of rust-lang#90575 - m-ou-se:compatible-variant-improvem…
Rollup merge of rust-lang#90575 - m-ou-se:compatible-variant-improvem…
Rollup merge of rust-lang#90575 - m-ou-se:compatible-variant-improvem…
Rollup merge of rust-lang#90575 - m-ou-se:compatible-variant-improvem…
m-ou-se commentedon Jan 19, 2022
Re-opening this, because it doesn't work yet for
forloops:Rollup merge of rust-lang#93072 - m-ou-se:compatible-variants-suggest…
Rollup merge of rust-lang#93072 - m-ou-se:compatible-variants-suggest…
Rollup merge of rust-lang#93072 - m-ou-se:compatible-variants-suggest…
Rollup merge of rust-lang#93072 - m-ou-se:compatible-variants-suggest…