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
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 ==
The text was updated successfully, but these errors were encountered:
Report error for assignment in `if` condition
For code like `if x = 3 {}`, output:
```
error[E0308]: mismatched types
--> $DIR/issue-17283.rs:25:8
|
25 | if x = x {
| ^^^^^
| |
| help: did you mean to compare equality? `x == x`
| expected bool, found ()
|
= note: expected type `bool`
found type `()`
```
Fix#40926.
cc #17283
currently reports
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
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
==
The text was updated successfully, but these errors were encountered: