Closed
Description
cc #17283
if x = 3 { }
currently reports
error[E0308]: mismatched types
--> <anon>:3:8
|
3 | if x = 3 { }
| ^^^^^ expected bool, found ()
|
= note: expected type `bool`
found type `()`
Not only is the note and the label redundant, but imo there should be a note/suggestion asking the user whether they meant x == 3
.
Similarly, if the arguments are swapped, one gets a
error[E0070]: invalid left-hand side expression
--> <anon>:3:8
|
3 | if 3 = x { }
| ^^^^^ left-hand of expression not valid
error[E0308]: mismatched types
--> <anon>:3:8
|
3 | if 3 = x { }
| ^^^^^ expected bool, found ()
|
= note: expected type `bool`
found type `()`
The second error is bogus in this situation. The assignment is invalid, so the result type doesn't matter at all.
The first error should also be suggesting to use ==