Skip to content

Commit 05d59fe

Browse files
committed
add test for assignment x = y where type bool is expected.
1 parent 7945eff commit 05d59fe

File tree

2 files changed

+164
-0
lines changed

2 files changed

+164
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// The purpose of this text is to ensure that we get good
2+
// diagnostics when a `bool` is expected but that due to
3+
// an assignment expression `x = y` the type is `()`.
4+
5+
fn main() {
6+
let _: bool = 0 = 0; //~ ERROR mismatched types [E0308]
7+
8+
let _: bool = match 0 {
9+
0 => 0 = 0, //~ ERROR mismatched types [E0308]
10+
_ => 0 = 0, //~ ERROR mismatched types [E0308]
11+
};
12+
13+
let _: bool = match true {
14+
true => 0 = 0, //~ ERROR mismatched types [E0308]
15+
_ => (),
16+
};
17+
18+
if 0 = 0 {} //~ ERROR mismatched types [E0308]
19+
20+
let _: bool = if { 0 = 0 } { //~ ERROR mismatched types [E0308]
21+
0 = 0 //~ ERROR mismatched types [E0308]
22+
} else {
23+
0 = 0 //~ ERROR mismatched types [E0308]
24+
};
25+
26+
let _ = (0 = 0) //~ ERROR mismatched types [E0308]
27+
&& { 0 = 0 } //~ ERROR mismatched types [E0308]
28+
|| (0 = 0); //~ ERROR mismatched types [E0308]
29+
}
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/assignment-expected-bool.rs:6:19
3+
|
4+
LL | let _: bool = 0 = 0;
5+
| ^^^^^
6+
| |
7+
| expected bool, found ()
8+
| help: try comparing for equality: `0 == 0`
9+
|
10+
= note: expected type `bool`
11+
found type `()`
12+
13+
error[E0308]: mismatched types
14+
--> $DIR/assignment-expected-bool.rs:9:14
15+
|
16+
LL | 0 => 0 = 0,
17+
| ^^^^^
18+
| |
19+
| expected bool, found ()
20+
| help: try comparing for equality: `0 == 0`
21+
|
22+
= note: expected type `bool`
23+
found type `()`
24+
25+
error[E0308]: mismatched types
26+
--> $DIR/assignment-expected-bool.rs:10:14
27+
|
28+
LL | _ => 0 = 0,
29+
| ^^^^^
30+
| |
31+
| expected bool, found ()
32+
| help: try comparing for equality: `0 == 0`
33+
|
34+
= note: expected type `bool`
35+
found type `()`
36+
37+
error[E0308]: mismatched types
38+
--> $DIR/assignment-expected-bool.rs:14:17
39+
|
40+
LL | true => 0 = 0,
41+
| ^^^^^
42+
| |
43+
| expected bool, found ()
44+
| help: try comparing for equality: `0 == 0`
45+
|
46+
= note: expected type `bool`
47+
found type `()`
48+
49+
error[E0308]: mismatched types
50+
--> $DIR/assignment-expected-bool.rs:18:8
51+
|
52+
LL | if 0 = 0 {}
53+
| ^^^^^
54+
| |
55+
| expected bool, found ()
56+
| help: try comparing for equality: `0 == 0`
57+
|
58+
= note: expected type `bool`
59+
found type `()`
60+
61+
error[E0308]: mismatched types
62+
--> $DIR/assignment-expected-bool.rs:20:24
63+
|
64+
LL | let _: bool = if { 0 = 0 } {
65+
| ^^^^^
66+
| |
67+
| expected bool, found ()
68+
| help: try comparing for equality: `0 == 0`
69+
|
70+
= note: expected type `bool`
71+
found type `()`
72+
73+
error[E0308]: mismatched types
74+
--> $DIR/assignment-expected-bool.rs:21:9
75+
|
76+
LL | 0 = 0
77+
| ^^^^^
78+
| |
79+
| expected bool, found ()
80+
| help: try comparing for equality: `0 == 0`
81+
|
82+
= note: expected type `bool`
83+
found type `()`
84+
85+
error[E0308]: mismatched types
86+
--> $DIR/assignment-expected-bool.rs:23:9
87+
|
88+
LL | 0 = 0
89+
| ^^^^^
90+
| |
91+
| expected bool, found ()
92+
| help: try comparing for equality: `0 == 0`
93+
|
94+
= note: expected type `bool`
95+
found type `()`
96+
97+
error[E0308]: mismatched types
98+
--> $DIR/assignment-expected-bool.rs:26:13
99+
|
100+
LL | let _ = (0 = 0)
101+
| ^^^^^^^
102+
| |
103+
| expected bool, found ()
104+
| help: try comparing for equality: `0 == 0`
105+
|
106+
= note: expected type `bool`
107+
found type `()`
108+
109+
error[E0308]: mismatched types
110+
--> $DIR/assignment-expected-bool.rs:27:14
111+
|
112+
LL | && { 0 = 0 }
113+
| ^^^^^
114+
| |
115+
| expected bool, found ()
116+
| help: try comparing for equality: `0 == 0`
117+
|
118+
= note: expected type `bool`
119+
found type `()`
120+
121+
error[E0308]: mismatched types
122+
--> $DIR/assignment-expected-bool.rs:28:12
123+
|
124+
LL | || (0 = 0);
125+
| ^^^^^^^
126+
| |
127+
| expected bool, found ()
128+
| help: try comparing for equality: `0 == 0`
129+
|
130+
= note: expected type `bool`
131+
found type `()`
132+
133+
error: aborting due to 11 previous errors
134+
135+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)