Skip to content

Commit aaf2255

Browse files
authored
Rollup merge of rust-lang#94974 - c410-f3r:let-chain-dashufwrqwemkf-let-else, r=joshtriplett
Ensure that `let_else` does not interact with `let_chains` As requested on rust-lang#94927. cc `@joshtriplett` `@estebank`
2 parents 0732ea2 + 261d5fc commit aaf2255

File tree

2 files changed

+173
-0
lines changed

2 files changed

+173
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#![feature(let_chains, let_else)]
2+
3+
fn main() {
4+
let opt = Some(1i32);
5+
6+
let Some(n) = opt else {
7+
return;
8+
};
9+
let Some(n) = opt && n == 1 else {
10+
//~^ ERROR a `&&` expression cannot be directly assigned in `let...else`
11+
//~| ERROR mismatched types
12+
//~| ERROR mismatched types
13+
return;
14+
};
15+
let Some(n) = opt && let another = n else {
16+
//~^ ERROR a `&&` expression cannot be directly assigned in `let...else`
17+
//~| ERROR `let` expressions are not supported here
18+
//~| ERROR mismatched types
19+
//~| ERROR mismatched types
20+
return;
21+
};
22+
23+
if let Some(n) = opt else {
24+
//~^ ERROR missing condition for `if` expression
25+
return;
26+
};
27+
if let Some(n) = opt && n == 1 else {
28+
//~^ ERROR missing condition for `if` expression
29+
return;
30+
};
31+
if let Some(n) = opt && let another = n else {
32+
//~^ ERROR missing condition for `if` expression
33+
return;
34+
};
35+
36+
{
37+
while let Some(n) = opt else {
38+
//~^ ERROR expected `{`, found keyword `else`
39+
return;
40+
};
41+
}
42+
{
43+
while let Some(n) = opt && n == 1 else {
44+
//~^ ERROR expected `{`, found keyword `else`
45+
return;
46+
};
47+
}
48+
{
49+
while let Some(n) = opt && let another = n else {
50+
//~^ ERROR expected `{`, found keyword `else`
51+
return;
52+
};
53+
}
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
error: a `&&` expression cannot be directly assigned in `let...else`
2+
--> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:9:19
3+
|
4+
LL | let Some(n) = opt && n == 1 else {
5+
| ^^^^^^^^^^^^^
6+
|
7+
help: wrap the expression in parentheses
8+
|
9+
LL | let Some(n) = (opt && n == 1) else {
10+
| + +
11+
12+
error: a `&&` expression cannot be directly assigned in `let...else`
13+
--> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:15:19
14+
|
15+
LL | let Some(n) = opt && let another = n else {
16+
| ^^^^^^^^^^^^^^^^^^^^^^
17+
|
18+
help: wrap the expression in parentheses
19+
|
20+
LL | let Some(n) = (opt && let another = n) else {
21+
| + +
22+
23+
error: missing condition for `if` expression
24+
--> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:23:7
25+
|
26+
LL | if let Some(n) = opt else {
27+
| ^ expected if condition here
28+
29+
error: missing condition for `if` expression
30+
--> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:27:7
31+
|
32+
LL | if let Some(n) = opt && n == 1 else {
33+
| ^ expected if condition here
34+
35+
error: missing condition for `if` expression
36+
--> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:31:7
37+
|
38+
LL | if let Some(n) = opt && let another = n else {
39+
| ^ expected if condition here
40+
41+
error: expected `{`, found keyword `else`
42+
--> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:37:33
43+
|
44+
LL | while let Some(n) = opt else {
45+
| ----- ----------------- ^^^^ expected `{`
46+
| | |
47+
| | this `while` condition successfully parsed
48+
| while parsing the body of this `while` expression
49+
50+
error: expected `{`, found keyword `else`
51+
--> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:43:43
52+
|
53+
LL | while let Some(n) = opt && n == 1 else {
54+
| ----- --------------------------- ^^^^ expected `{`
55+
| | |
56+
| | this `while` condition successfully parsed
57+
| while parsing the body of this `while` expression
58+
59+
error: expected `{`, found keyword `else`
60+
--> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:49:52
61+
|
62+
LL | while let Some(n) = opt && let another = n else {
63+
| ----- ------------------------------------ ^^^^ expected `{`
64+
| | |
65+
| | this `while` condition successfully parsed
66+
| while parsing the body of this `while` expression
67+
68+
error: `let` expressions are not supported here
69+
--> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:15:26
70+
|
71+
LL | let Some(n) = opt && let another = n else {
72+
| ^^^^^^^^^^^^^^^
73+
|
74+
= note: only supported directly in conditions of `if` and `while` expressions
75+
= note: as well as when nested within `&&` and parentheses in those conditions
76+
77+
error[E0308]: mismatched types
78+
--> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:9:19
79+
|
80+
LL | let Some(n) = opt && n == 1 else {
81+
| ^^^ expected `bool`, found enum `Option`
82+
|
83+
= note: expected type `bool`
84+
found enum `Option<i32>`
85+
86+
error[E0308]: mismatched types
87+
--> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:9:9
88+
|
89+
LL | let Some(n) = opt && n == 1 else {
90+
| ^^^^^^^ ------------- this expression has type `bool`
91+
| |
92+
| expected `bool`, found enum `Option`
93+
|
94+
= note: expected type `bool`
95+
found enum `Option<_>`
96+
97+
error[E0308]: mismatched types
98+
--> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:15:19
99+
|
100+
LL | let Some(n) = opt && let another = n else {
101+
| ^^^ expected `bool`, found enum `Option`
102+
|
103+
= note: expected type `bool`
104+
found enum `Option<i32>`
105+
106+
error[E0308]: mismatched types
107+
--> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:15:9
108+
|
109+
LL | let Some(n) = opt && let another = n else {
110+
| ^^^^^^^ ---------------------- this expression has type `bool`
111+
| |
112+
| expected `bool`, found enum `Option`
113+
|
114+
= note: expected type `bool`
115+
found enum `Option<_>`
116+
117+
error: aborting due to 13 previous errors
118+
119+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)