resolved conflict

This commit is contained in:
Kivooeo 2025-04-25 15:55:44 +05:00
parent 847e3ee6b0
commit f072d30741
12 changed files with 100 additions and 63 deletions

View File

@ -675,6 +675,8 @@ parse_note_pattern_alternatives_use_single_vert = alternatives in or-patterns ar
parse_nul_in_c_str = null characters in C string literals are not supported
parse_or_in_let_chain = `||` operators are not supported in let chain conditions
parse_or_pattern_not_allowed_in_fn_parameters = top-level or-patterns are not allowed in function parameters
parse_or_pattern_not_allowed_in_let_binding = top-level or-patterns are not allowed in `let` bindings
parse_out_of_range_hex_escape = out of range hex escape

View File

@ -478,6 +478,13 @@ pub(crate) struct ExpectedExpressionFoundLet {
pub comparison: Option<MaybeComparison>,
}
#[derive(Diagnostic)]
#[diag(parse_or_in_let_chain)]
pub(crate) struct OrInLetChain {
#[primary_span]
pub span: Span,
}
#[derive(Subdiagnostic, Clone, Copy)]
#[multipart_suggestion(
parse_maybe_missing_let,

View File

@ -4073,14 +4073,18 @@ impl MutVisitor for CondChecker<'_> {
match e.kind {
ExprKind::Let(_, _, _, ref mut recovered @ Recovered::No) => {
if let Some(reason) = self.forbid_let_reason {
*recovered = Recovered::Yes(self.parser.dcx().emit_err(
errors::ExpectedExpressionFoundLet {
let error = match reason {
NotSupportedOr(or_span) => {
self.parser.dcx().emit_err(errors::OrInLetChain { span: or_span })
}
_ => self.parser.dcx().emit_err(errors::ExpectedExpressionFoundLet {
span,
reason,
missing_let: self.missing_let,
comparison: self.comparison,
},
));
}),
};
*recovered = Recovered::Yes(error);
} else if self.depth > 1 {
// Top level `let` is always allowed; only gate chains
match self.let_chains_policy {

View File

@ -0,0 +1,28 @@
error: `||` operators are not supported in let chain conditions
--> $DIR/or-in-let-chain.rs:6:24
|
LL | if let true = true || false {}
| ^^
error: expected expression, found `let` statement
--> $DIR/or-in-let-chain.rs:9:9
|
LL | if (let true = true) || false {}
| ^^^^^^^^^^^^^^^
|
= note: only supported directly in conditions of `if` and `while` expressions
error: `||` operators are not supported in let chain conditions
--> $DIR/or-in-let-chain.rs:12:24
|
LL | if let true = true || false || true {}
| ^^
error: `||` operators are not supported in let chain conditions
--> $DIR/or-in-let-chain.rs:15:33
|
LL | if let true = true && false || true {}
| ^^
error: aborting due to 4 previous errors

View File

@ -0,0 +1,28 @@
error: `||` operators are not supported in let chain conditions
--> $DIR/or-in-let-chain.rs:6:24
|
LL | if let true = true || false {}
| ^^
error: expected expression, found `let` statement
--> $DIR/or-in-let-chain.rs:9:9
|
LL | if (let true = true) || false {}
| ^^^^^^^^^^^^^^^
|
= note: only supported directly in conditions of `if` and `while` expressions
error: `||` operators are not supported in let chain conditions
--> $DIR/or-in-let-chain.rs:12:24
|
LL | if let true = true || false || true {}
| ^^
error: `||` operators are not supported in let chain conditions
--> $DIR/or-in-let-chain.rs:15:33
|
LL | if let true = true && false || true {}
| ^^
error: aborting due to 4 previous errors

View File

@ -0,0 +1,17 @@
//@ revisions: edition2021 edition2024
//@ [edition2021] edition: 2021
//@ [edition2024] edition: 2024
fn main() {
if let true = true || false {}
//~^ ERROR `||` operators are not supported in let chain conditions
// With parentheses
if (let true = true) || false {}
//~^ ERROR expected expression, found `let` statement
// Multiple || operators
if let true = true || false || true {}
//~^ ERROR `||` operators are not supported in let chain conditions
// Mixed operators (should still show error for ||)
if let true = true && false || true {}
//~^ ERROR `||` operators are not supported in let chain conditions
}

View File

@ -3,7 +3,7 @@
fn let_or_guard(x: Result<Option<i32>, ()>) {
match x {
Ok(opt) if let Some(4) = opt || false => {}
//~^ ERROR expected expression, found `let` statement
//~^ ERROR `||` operators are not supported in let chain conditions
_ => {}
}
}

View File

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

View File

@ -272,14 +272,7 @@ LL | if (let 0 = 0)? {}
|
= note: only supported directly in conditions of `if` and `while` expressions
error: expected expression, found `let` statement
--> $DIR/disallowed-positions.rs:121:16
|
LL | if true || let 0 = 0 {}
| ^^^^^^^^^
|
= note: only supported directly in conditions of `if` and `while` expressions
note: `||` operators are not supported in let chain expressions
error: `||` operators are not supported in let chain conditions
--> $DIR/disallowed-positions.rs:121:13
|
LL | if true || let 0 = 0 {}
@ -485,14 +478,7 @@ LL | while (let 0 = 0)? {}
|
= note: only supported directly in conditions of `if` and `while` expressions
error: expected expression, found `let` statement
--> $DIR/disallowed-positions.rs:212:19
|
LL | while true || let 0 = 0 {}
| ^^^^^^^^^
|
= note: only supported directly in conditions of `if` and `while` expressions
note: `||` operators are not supported in let chain expressions
error: `||` operators are not supported in let chain conditions
--> $DIR/disallowed-positions.rs:212:16
|
LL | while true || let 0 = 0 {}

View File

@ -272,14 +272,7 @@ LL | if (let 0 = 0)? {}
|
= note: only supported directly in conditions of `if` and `while` expressions
error: expected expression, found `let` statement
--> $DIR/disallowed-positions.rs:121:16
|
LL | if true || let 0 = 0 {}
| ^^^^^^^^^
|
= note: only supported directly in conditions of `if` and `while` expressions
note: `||` operators are not supported in let chain expressions
error: `||` operators are not supported in let chain conditions
--> $DIR/disallowed-positions.rs:121:13
|
LL | if true || let 0 = 0 {}
@ -485,14 +478,7 @@ LL | while (let 0 = 0)? {}
|
= note: only supported directly in conditions of `if` and `while` expressions
error: expected expression, found `let` statement
--> $DIR/disallowed-positions.rs:212:19
|
LL | while true || let 0 = 0 {}
| ^^^^^^^^^
|
= note: only supported directly in conditions of `if` and `while` expressions
note: `||` operators are not supported in let chain expressions
error: `||` operators are not supported in let chain conditions
--> $DIR/disallowed-positions.rs:212:16
|
LL | while true || let 0 = 0 {}

View File

@ -272,14 +272,7 @@ LL | if (let 0 = 0)? {}
|
= note: only supported directly in conditions of `if` and `while` expressions
error: expected expression, found `let` statement
--> $DIR/disallowed-positions.rs:121:16
|
LL | if true || let 0 = 0 {}
| ^^^^^^^^^
|
= note: only supported directly in conditions of `if` and `while` expressions
note: `||` operators are not supported in let chain expressions
error: `||` operators are not supported in let chain conditions
--> $DIR/disallowed-positions.rs:121:13
|
LL | if true || let 0 = 0 {}
@ -485,14 +478,7 @@ LL | while (let 0 = 0)? {}
|
= note: only supported directly in conditions of `if` and `while` expressions
error: expected expression, found `let` statement
--> $DIR/disallowed-positions.rs:212:19
|
LL | while true || let 0 = 0 {}
| ^^^^^^^^^
|
= note: only supported directly in conditions of `if` and `while` expressions
note: `||` operators are not supported in let chain expressions
error: `||` operators are not supported in let chain conditions
--> $DIR/disallowed-positions.rs:212:16
|
LL | while true || let 0 = 0 {}

View File

@ -119,7 +119,7 @@ fn nested_within_if_expr() {
//~^ ERROR expected expression, found `let` statement
if true || let 0 = 0 {}
//~^ ERROR expected expression, found `let` statement
//~^ ERROR `||` operators are not supported in let chain conditions
if (true || let 0 = 0) {}
//~^ ERROR expected expression, found `let` statement
if true && (true || let 0 = 0) {}
@ -210,7 +210,7 @@ fn nested_within_while_expr() {
//~^ ERROR expected expression, found `let` statement
while true || let 0 = 0 {}
//~^ ERROR expected expression, found `let` statement
//~^ ERROR `||` operators are not supported in let chain conditions
while (true || let 0 = 0) {}
//~^ ERROR expected expression, found `let` statement
while true && (true || let 0 = 0) {}