Skip to content

Commit 9e15f56

Browse files
committed
resolved conflict
1 parent d44c66d commit 9e15f56

File tree

9 files changed

+98
-17
lines changed

9 files changed

+98
-17
lines changed

compiler/rustc_parse/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ parse_expected_expression_found_let = expected expression, found `let` statement
209209
.not_supported_or = `||` operators are not supported in let chain expressions
210210
.not_supported_parentheses = `let`s wrapped in parentheses are not supported in a context with let chains
211211
212+
parse_or_in_let_chain = `||` operators are not supported in let chain conditions
213+
212214
parse_expected_fn_path_found_fn_keyword = expected identifier, found keyword `fn`
213215
.suggestion = use `Fn` to refer to the trait
214216

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:10: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:14: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:18: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:10: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:14: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:18: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

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
9+
// With parentheses
10+
if (let true = true) || false {}
11+
//~^ ERROR expected expression, found `let` statement
12+
13+
// Multiple || operators
14+
if let true = true || false || true {}
15+
//~^ ERROR `||` operators are not supported in let chain conditions
16+
17+
// Mixed operators (should still show error for ||)
18+
if let true = true && false || true {}
19+
//~^ ERROR `||` operators are not supported in let chain conditions
20+
}

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

+2-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
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
|
11-
LL | Ok(opt) if let Some(4) = opt || false => {}
12-
| ^^
4+
LL | Ok(opt) if let Some(4) = opt || false => {} ^^
135

146
error: module cannot be declared unsafe
157
--> $DIR/ast-validate-guards.rs:15:17

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)