-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #42649 - estebank:if-cond, r=nikomatsakis
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.
- Loading branch information
Showing
5 changed files
with
145 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/assignment-in-if.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 `()` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/assignment-in-if.rs:31:8 | ||
| | ||
31 | if (x = x) { | ||
| ^^^^^^^ | ||
| | | ||
| help: did you mean to compare equality? `x == x` | ||
| expected bool, found () | ||
| | ||
= note: expected type `bool` | ||
found type `()` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/assignment-in-if.rs:37:8 | ||
| | ||
37 | if y = (Foo { foo: x }) { | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| help: did you mean to compare equality? `y == (Foo { foo: x })` | ||
| expected bool, found () | ||
| | ||
= note: expected type `bool` | ||
found type `()` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/assignment-in-if.rs:43:8 | ||
| | ||
43 | if 3 = x { | ||
| ^^^^^ | ||
| | | ||
| help: did you mean to compare equality? `3 == x` | ||
| expected bool, found () | ||
| | ||
= note: expected type `bool` | ||
found type `()` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/assignment-in-if.rs:48:8 | ||
| | ||
48 | if (if true { x = 4 } else { x = 5 }) { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected bool, found () | ||
| | ||
= note: expected type `bool` | ||
found type `()` | ||
|
||
error: aborting due to previous error(s) | ||
|