Skip to content

Commit f072d30

Browse files
committed
resolved conflict
1 parent 847e3ee commit f072d30

12 files changed

+100
-63
lines changed

compiler/rustc_parse/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,8 @@ parse_note_pattern_alternatives_use_single_vert = alternatives in or-patterns ar
675675
676676
parse_nul_in_c_str = null characters in C string literals are not supported
677677
678+
parse_or_in_let_chain = `||` operators are not supported in let chain conditions
679+
678680
parse_or_pattern_not_allowed_in_fn_parameters = top-level or-patterns are not allowed in function parameters
679681
parse_or_pattern_not_allowed_in_let_binding = top-level or-patterns are not allowed in `let` bindings
680682
parse_out_of_range_hex_escape = out of range hex escape

compiler/rustc_parse/src/errors.rs

+7
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,13 @@ pub(crate) struct ExpectedExpressionFoundLet {
478478
pub comparison: Option<MaybeComparison>,
479479
}
480480

481+
#[derive(Diagnostic)]
482+
#[diag(parse_or_in_let_chain)]
483+
pub(crate) struct OrInLetChain {
484+
#[primary_span]
485+
pub span: Span,
486+
}
487+
481488
#[derive(Subdiagnostic, Clone, Copy)]
482489
#[multipart_suggestion(
483490
parse_maybe_missing_let,

compiler/rustc_parse/src/parser/expr.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -4073,14 +4073,18 @@ impl MutVisitor for CondChecker<'_> {
40734073
match e.kind {
40744074
ExprKind::Let(_, _, _, ref mut recovered @ Recovered::No) => {
40754075
if let Some(reason) = self.forbid_let_reason {
4076-
*recovered = Recovered::Yes(self.parser.dcx().emit_err(
4077-
errors::ExpectedExpressionFoundLet {
4076+
let error = match reason {
4077+
NotSupportedOr(or_span) => {
4078+
self.parser.dcx().emit_err(errors::OrInLetChain { span: or_span })
4079+
}
4080+
_ => self.parser.dcx().emit_err(errors::ExpectedExpressionFoundLet {
40784081
span,
40794082
reason,
40804083
missing_let: self.missing_let,
40814084
comparison: self.comparison,
4082-
},
4083-
));
4085+
}),
4086+
};
4087+
*recovered = Recovered::Yes(error);
40844088
} else if self.depth > 1 {
40854089
// Top level `let` is always allowed; only gate chains
40864090
match self.let_chains_policy {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
error: `||` operators are not supported in let chain conditions
2+
--> $DIR/or-in-let-chain.rs:6:24
3+
|
4+
LL | if let true = true || false {}
5+
| ^^
6+
7+
error: expected expression, found `let` statement
8+
--> $DIR/or-in-let-chain.rs:9:9
9+
|
10+
LL | if (let true = true) || false {}
11+
| ^^^^^^^^^^^^^^^
12+
|
13+
= note: only supported directly in conditions of `if` and `while` expressions
14+
15+
error: `||` operators are not supported in let chain conditions
16+
--> $DIR/or-in-let-chain.rs:12:24
17+
|
18+
LL | if let true = true || false || true {}
19+
| ^^
20+
21+
error: `||` operators are not supported in let chain conditions
22+
--> $DIR/or-in-let-chain.rs:15:33
23+
|
24+
LL | if let true = true && false || true {}
25+
| ^^
26+
27+
error: aborting due to 4 previous errors
28+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
error: `||` operators are not supported in let chain conditions
2+
--> $DIR/or-in-let-chain.rs:6:24
3+
|
4+
LL | if let true = true || false {}
5+
| ^^
6+
7+
error: expected expression, found `let` statement
8+
--> $DIR/or-in-let-chain.rs:9:9
9+
|
10+
LL | if (let true = true) || false {}
11+
| ^^^^^^^^^^^^^^^
12+
|
13+
= note: only supported directly in conditions of `if` and `while` expressions
14+
15+
error: `||` operators are not supported in let chain conditions
16+
--> $DIR/or-in-let-chain.rs:12:24
17+
|
18+
LL | if let true = true || false || true {}
19+
| ^^
20+
21+
error: `||` operators are not supported in let chain conditions
22+
--> $DIR/or-in-let-chain.rs:15:33
23+
|
24+
LL | if let true = true && false || true {}
25+
| ^^
26+
27+
error: aborting due to 4 previous errors
28+

tests/ui/parser/or-in-let-chain.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@ revisions: edition2021 edition2024
2+
//@ [edition2021] edition: 2021
3+
//@ [edition2024] edition: 2024
4+
5+
fn main() {
6+
if let true = true || false {}
7+
//~^ ERROR `||` operators are not supported in let chain conditions
8+
// With parentheses
9+
if (let true = true) || false {}
10+
//~^ ERROR expected expression, found `let` statement
11+
// Multiple || operators
12+
if let true = true || false || true {}
13+
//~^ ERROR `||` operators are not supported in let chain conditions
14+
// Mixed operators (should still show error for ||)
15+
if let true = true && false || true {}
16+
//~^ ERROR `||` operators are not supported in let chain conditions
17+
}

tests/ui/rfcs/rfc-2497-if-let-chains/ast-validate-guards.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
fn let_or_guard(x: Result<Option<i32>, ()>) {
44
match x {
55
Ok(opt) if let Some(4) = opt || false => {}
6-
//~^ ERROR expected expression, found `let` statement
6+
//~^ ERROR `||` operators are not supported in let chain conditions
77
_ => {}
88
}
99
}

tests/ui/rfcs/rfc-2497-if-let-chains/ast-validate-guards.stderr

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
error: expected expression, found `let` statement
2-
--> $DIR/ast-validate-guards.rs:5:20
3-
|
4-
LL | Ok(opt) if let Some(4) = opt || false => {}
5-
| ^^^^^^^^^^^^^^^^^
6-
|
7-
= note: only supported directly in conditions of `if` and `while` expressions
8-
note: `||` operators are not supported in let chain expressions
1+
error: `||` operators are not supported in let chain conditions
92
--> $DIR/ast-validate-guards.rs:5:38
103
|
114
LL | Ok(opt) if let Some(4) = opt || false => {}

tests/ui/rfcs/rfc-2497-if-let-chains/disallowed-positions.feature.stderr

+2-16
Original file line numberDiff line numberDiff line change
@@ -272,14 +272,7 @@ LL | if (let 0 = 0)? {}
272272
|
273273
= note: only supported directly in conditions of `if` and `while` expressions
274274

275-
error: expected expression, found `let` statement
276-
--> $DIR/disallowed-positions.rs:121:16
277-
|
278-
LL | if true || let 0 = 0 {}
279-
| ^^^^^^^^^
280-
|
281-
= note: only supported directly in conditions of `if` and `while` expressions
282-
note: `||` operators are not supported in let chain expressions
275+
error: `||` operators are not supported in let chain conditions
283276
--> $DIR/disallowed-positions.rs:121:13
284277
|
285278
LL | if true || let 0 = 0 {}
@@ -485,14 +478,7 @@ LL | while (let 0 = 0)? {}
485478
|
486479
= note: only supported directly in conditions of `if` and `while` expressions
487480

488-
error: expected expression, found `let` statement
489-
--> $DIR/disallowed-positions.rs:212:19
490-
|
491-
LL | while true || let 0 = 0 {}
492-
| ^^^^^^^^^
493-
|
494-
= note: only supported directly in conditions of `if` and `while` expressions
495-
note: `||` operators are not supported in let chain expressions
481+
error: `||` operators are not supported in let chain conditions
496482
--> $DIR/disallowed-positions.rs:212:16
497483
|
498484
LL | while true || let 0 = 0 {}

tests/ui/rfcs/rfc-2497-if-let-chains/disallowed-positions.no_feature.stderr

+2-16
Original file line numberDiff line numberDiff line change
@@ -272,14 +272,7 @@ LL | if (let 0 = 0)? {}
272272
|
273273
= note: only supported directly in conditions of `if` and `while` expressions
274274

275-
error: expected expression, found `let` statement
276-
--> $DIR/disallowed-positions.rs:121:16
277-
|
278-
LL | if true || let 0 = 0 {}
279-
| ^^^^^^^^^
280-
|
281-
= note: only supported directly in conditions of `if` and `while` expressions
282-
note: `||` operators are not supported in let chain expressions
275+
error: `||` operators are not supported in let chain conditions
283276
--> $DIR/disallowed-positions.rs:121:13
284277
|
285278
LL | if true || let 0 = 0 {}
@@ -485,14 +478,7 @@ LL | while (let 0 = 0)? {}
485478
|
486479
= note: only supported directly in conditions of `if` and `while` expressions
487480

488-
error: expected expression, found `let` statement
489-
--> $DIR/disallowed-positions.rs:212:19
490-
|
491-
LL | while true || let 0 = 0 {}
492-
| ^^^^^^^^^
493-
|
494-
= note: only supported directly in conditions of `if` and `while` expressions
495-
note: `||` operators are not supported in let chain expressions
481+
error: `||` operators are not supported in let chain conditions
496482
--> $DIR/disallowed-positions.rs:212:16
497483
|
498484
LL | while true || let 0 = 0 {}

tests/ui/rfcs/rfc-2497-if-let-chains/disallowed-positions.nothing.stderr

+2-16
Original file line numberDiff line numberDiff line change
@@ -272,14 +272,7 @@ LL | if (let 0 = 0)? {}
272272
|
273273
= note: only supported directly in conditions of `if` and `while` expressions
274274

275-
error: expected expression, found `let` statement
276-
--> $DIR/disallowed-positions.rs:121:16
277-
|
278-
LL | if true || let 0 = 0 {}
279-
| ^^^^^^^^^
280-
|
281-
= note: only supported directly in conditions of `if` and `while` expressions
282-
note: `||` operators are not supported in let chain expressions
275+
error: `||` operators are not supported in let chain conditions
283276
--> $DIR/disallowed-positions.rs:121:13
284277
|
285278
LL | if true || let 0 = 0 {}
@@ -485,14 +478,7 @@ LL | while (let 0 = 0)? {}
485478
|
486479
= note: only supported directly in conditions of `if` and `while` expressions
487480

488-
error: expected expression, found `let` statement
489-
--> $DIR/disallowed-positions.rs:212:19
490-
|
491-
LL | while true || let 0 = 0 {}
492-
| ^^^^^^^^^
493-
|
494-
= note: only supported directly in conditions of `if` and `while` expressions
495-
note: `||` operators are not supported in let chain expressions
481+
error: `||` operators are not supported in let chain conditions
496482
--> $DIR/disallowed-positions.rs:212:16
497483
|
498484
LL | while true || let 0 = 0 {}

tests/ui/rfcs/rfc-2497-if-let-chains/disallowed-positions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ fn nested_within_if_expr() {
119119
//~^ ERROR expected expression, found `let` statement
120120

121121
if true || let 0 = 0 {}
122-
//~^ ERROR expected expression, found `let` statement
122+
//~^ ERROR `||` operators are not supported in let chain conditions
123123
if (true || let 0 = 0) {}
124124
//~^ ERROR expected expression, found `let` statement
125125
if true && (true || let 0 = 0) {}
@@ -210,7 +210,7 @@ fn nested_within_while_expr() {
210210
//~^ ERROR expected expression, found `let` statement
211211

212212
while true || let 0 = 0 {}
213-
//~^ ERROR expected expression, found `let` statement
213+
//~^ ERROR `||` operators are not supported in let chain conditions
214214
while (true || let 0 = 0) {}
215215
//~^ ERROR expected expression, found `let` statement
216216
while true && (true || let 0 = 0) {}

0 commit comments

Comments
 (0)