add test for assignment x = y where type bool is expected.

This commit is contained in:
Mazdak Farrokhzad 2019-03-26 14:56:32 +01:00
parent 7945eff080
commit 05d59feb64
2 changed files with 164 additions and 0 deletions

View file

@ -0,0 +1,29 @@
// The purpose of this text is to ensure that we get good
// diagnostics when a `bool` is expected but that due to
// an assignment expression `x = y` the type is `()`.
fn main() {
let _: bool = 0 = 0; //~ ERROR mismatched types [E0308]
let _: bool = match 0 {
0 => 0 = 0, //~ ERROR mismatched types [E0308]
_ => 0 = 0, //~ ERROR mismatched types [E0308]
};
let _: bool = match true {
true => 0 = 0, //~ ERROR mismatched types [E0308]
_ => (),
};
if 0 = 0 {} //~ ERROR mismatched types [E0308]
let _: bool = if { 0 = 0 } { //~ ERROR mismatched types [E0308]
0 = 0 //~ ERROR mismatched types [E0308]
} else {
0 = 0 //~ ERROR mismatched types [E0308]
};
let _ = (0 = 0) //~ ERROR mismatched types [E0308]
&& { 0 = 0 } //~ ERROR mismatched types [E0308]
|| (0 = 0); //~ ERROR mismatched types [E0308]
}

View file

@ -0,0 +1,135 @@
error[E0308]: mismatched types
--> $DIR/assignment-expected-bool.rs:6:19
|
LL | let _: bool = 0 = 0;
| ^^^^^
| |
| expected bool, found ()
| help: try comparing for equality: `0 == 0`
|
= note: expected type `bool`
found type `()`
error[E0308]: mismatched types
--> $DIR/assignment-expected-bool.rs:9:14
|
LL | 0 => 0 = 0,
| ^^^^^
| |
| expected bool, found ()
| help: try comparing for equality: `0 == 0`
|
= note: expected type `bool`
found type `()`
error[E0308]: mismatched types
--> $DIR/assignment-expected-bool.rs:10:14
|
LL | _ => 0 = 0,
| ^^^^^
| |
| expected bool, found ()
| help: try comparing for equality: `0 == 0`
|
= note: expected type `bool`
found type `()`
error[E0308]: mismatched types
--> $DIR/assignment-expected-bool.rs:14:17
|
LL | true => 0 = 0,
| ^^^^^
| |
| expected bool, found ()
| help: try comparing for equality: `0 == 0`
|
= note: expected type `bool`
found type `()`
error[E0308]: mismatched types
--> $DIR/assignment-expected-bool.rs:18:8
|
LL | if 0 = 0 {}
| ^^^^^
| |
| expected bool, found ()
| help: try comparing for equality: `0 == 0`
|
= note: expected type `bool`
found type `()`
error[E0308]: mismatched types
--> $DIR/assignment-expected-bool.rs:20:24
|
LL | let _: bool = if { 0 = 0 } {
| ^^^^^
| |
| expected bool, found ()
| help: try comparing for equality: `0 == 0`
|
= note: expected type `bool`
found type `()`
error[E0308]: mismatched types
--> $DIR/assignment-expected-bool.rs:21:9
|
LL | 0 = 0
| ^^^^^
| |
| expected bool, found ()
| help: try comparing for equality: `0 == 0`
|
= note: expected type `bool`
found type `()`
error[E0308]: mismatched types
--> $DIR/assignment-expected-bool.rs:23:9
|
LL | 0 = 0
| ^^^^^
| |
| expected bool, found ()
| help: try comparing for equality: `0 == 0`
|
= note: expected type `bool`
found type `()`
error[E0308]: mismatched types
--> $DIR/assignment-expected-bool.rs:26:13
|
LL | let _ = (0 = 0)
| ^^^^^^^
| |
| expected bool, found ()
| help: try comparing for equality: `0 == 0`
|
= note: expected type `bool`
found type `()`
error[E0308]: mismatched types
--> $DIR/assignment-expected-bool.rs:27:14
|
LL | && { 0 = 0 }
| ^^^^^
| |
| expected bool, found ()
| help: try comparing for equality: `0 == 0`
|
= note: expected type `bool`
found type `()`
error[E0308]: mismatched types
--> $DIR/assignment-expected-bool.rs:28:12
|
LL | || (0 = 0);
| ^^^^^^^
| |
| expected bool, found ()
| help: try comparing for equality: `0 == 0`
|
= note: expected type `bool`
found type `()`
error: aborting due to 11 previous errors
For more information about this error, try `rustc --explain E0308`.