mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-07 23:47:39 +00:00
resolved conflict
This commit is contained in:
parent
847e3ee6b0
commit
f072d30741
@ -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_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_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_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
|
parse_out_of_range_hex_escape = out of range hex escape
|
||||||
|
@ -478,6 +478,13 @@ pub(crate) struct ExpectedExpressionFoundLet {
|
|||||||
pub comparison: Option<MaybeComparison>,
|
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)]
|
#[derive(Subdiagnostic, Clone, Copy)]
|
||||||
#[multipart_suggestion(
|
#[multipart_suggestion(
|
||||||
parse_maybe_missing_let,
|
parse_maybe_missing_let,
|
||||||
|
@ -4073,14 +4073,18 @@ impl MutVisitor for CondChecker<'_> {
|
|||||||
match e.kind {
|
match e.kind {
|
||||||
ExprKind::Let(_, _, _, ref mut recovered @ Recovered::No) => {
|
ExprKind::Let(_, _, _, ref mut recovered @ Recovered::No) => {
|
||||||
if let Some(reason) = self.forbid_let_reason {
|
if let Some(reason) = self.forbid_let_reason {
|
||||||
*recovered = Recovered::Yes(self.parser.dcx().emit_err(
|
let error = match reason {
|
||||||
errors::ExpectedExpressionFoundLet {
|
NotSupportedOr(or_span) => {
|
||||||
|
self.parser.dcx().emit_err(errors::OrInLetChain { span: or_span })
|
||||||
|
}
|
||||||
|
_ => self.parser.dcx().emit_err(errors::ExpectedExpressionFoundLet {
|
||||||
span,
|
span,
|
||||||
reason,
|
reason,
|
||||||
missing_let: self.missing_let,
|
missing_let: self.missing_let,
|
||||||
comparison: self.comparison,
|
comparison: self.comparison,
|
||||||
},
|
}),
|
||||||
));
|
};
|
||||||
|
*recovered = Recovered::Yes(error);
|
||||||
} else if self.depth > 1 {
|
} else if self.depth > 1 {
|
||||||
// Top level `let` is always allowed; only gate chains
|
// Top level `let` is always allowed; only gate chains
|
||||||
match self.let_chains_policy {
|
match self.let_chains_policy {
|
||||||
|
28
tests/ui/parser/or-in-let-chain.edition2021.stderr
Normal file
28
tests/ui/parser/or-in-let-chain.edition2021.stderr
Normal 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
|
||||||
|
|
28
tests/ui/parser/or-in-let-chain.edition2024.stderr
Normal file
28
tests/ui/parser/or-in-let-chain.edition2024.stderr
Normal 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
|
||||||
|
|
17
tests/ui/parser/or-in-let-chain.rs
Normal file
17
tests/ui/parser/or-in-let-chain.rs
Normal 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
|
||||||
|
}
|
@ -3,7 +3,7 @@
|
|||||||
fn let_or_guard(x: Result<Option<i32>, ()>) {
|
fn let_or_guard(x: Result<Option<i32>, ()>) {
|
||||||
match x {
|
match x {
|
||||||
Ok(opt) if let Some(4) = opt || false => {}
|
Ok(opt) if let Some(4) = opt || false => {}
|
||||||
//~^ ERROR expected expression, found `let` statement
|
//~^ ERROR `||` operators are not supported in let chain conditions
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,4 @@
|
|||||||
error: expected expression, found `let` statement
|
error: `||` operators are not supported in let chain conditions
|
||||||
--> $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
|
|
||||||
--> $DIR/ast-validate-guards.rs:5:38
|
--> $DIR/ast-validate-guards.rs:5:38
|
||||||
|
|
|
|
||||||
LL | Ok(opt) if let Some(4) = opt || false => {}
|
LL | Ok(opt) if let Some(4) = opt || false => {}
|
||||||
|
@ -272,14 +272,7 @@ LL | if (let 0 = 0)? {}
|
|||||||
|
|
|
|
||||||
= note: only supported directly in conditions of `if` and `while` expressions
|
= note: only supported directly in conditions of `if` and `while` expressions
|
||||||
|
|
||||||
error: expected expression, found `let` statement
|
error: `||` operators are not supported in let chain conditions
|
||||||
--> $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
|
|
||||||
--> $DIR/disallowed-positions.rs:121:13
|
--> $DIR/disallowed-positions.rs:121:13
|
||||||
|
|
|
|
||||||
LL | if true || let 0 = 0 {}
|
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
|
= note: only supported directly in conditions of `if` and `while` expressions
|
||||||
|
|
||||||
error: expected expression, found `let` statement
|
error: `||` operators are not supported in let chain conditions
|
||||||
--> $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
|
|
||||||
--> $DIR/disallowed-positions.rs:212:16
|
--> $DIR/disallowed-positions.rs:212:16
|
||||||
|
|
|
|
||||||
LL | while true || let 0 = 0 {}
|
LL | while true || let 0 = 0 {}
|
||||||
|
@ -272,14 +272,7 @@ LL | if (let 0 = 0)? {}
|
|||||||
|
|
|
|
||||||
= note: only supported directly in conditions of `if` and `while` expressions
|
= note: only supported directly in conditions of `if` and `while` expressions
|
||||||
|
|
||||||
error: expected expression, found `let` statement
|
error: `||` operators are not supported in let chain conditions
|
||||||
--> $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
|
|
||||||
--> $DIR/disallowed-positions.rs:121:13
|
--> $DIR/disallowed-positions.rs:121:13
|
||||||
|
|
|
|
||||||
LL | if true || let 0 = 0 {}
|
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
|
= note: only supported directly in conditions of `if` and `while` expressions
|
||||||
|
|
||||||
error: expected expression, found `let` statement
|
error: `||` operators are not supported in let chain conditions
|
||||||
--> $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
|
|
||||||
--> $DIR/disallowed-positions.rs:212:16
|
--> $DIR/disallowed-positions.rs:212:16
|
||||||
|
|
|
|
||||||
LL | while true || let 0 = 0 {}
|
LL | while true || let 0 = 0 {}
|
||||||
|
@ -272,14 +272,7 @@ LL | if (let 0 = 0)? {}
|
|||||||
|
|
|
|
||||||
= note: only supported directly in conditions of `if` and `while` expressions
|
= note: only supported directly in conditions of `if` and `while` expressions
|
||||||
|
|
||||||
error: expected expression, found `let` statement
|
error: `||` operators are not supported in let chain conditions
|
||||||
--> $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
|
|
||||||
--> $DIR/disallowed-positions.rs:121:13
|
--> $DIR/disallowed-positions.rs:121:13
|
||||||
|
|
|
|
||||||
LL | if true || let 0 = 0 {}
|
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
|
= note: only supported directly in conditions of `if` and `while` expressions
|
||||||
|
|
||||||
error: expected expression, found `let` statement
|
error: `||` operators are not supported in let chain conditions
|
||||||
--> $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
|
|
||||||
--> $DIR/disallowed-positions.rs:212:16
|
--> $DIR/disallowed-positions.rs:212:16
|
||||||
|
|
|
|
||||||
LL | while true || let 0 = 0 {}
|
LL | while true || let 0 = 0 {}
|
||||||
|
@ -119,7 +119,7 @@ fn nested_within_if_expr() {
|
|||||||
//~^ ERROR expected expression, found `let` statement
|
//~^ ERROR expected expression, found `let` statement
|
||||||
|
|
||||||
if true || let 0 = 0 {}
|
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) {}
|
if (true || let 0 = 0) {}
|
||||||
//~^ ERROR expected expression, found `let` statement
|
//~^ ERROR expected expression, found `let` statement
|
||||||
if true && (true || let 0 = 0) {}
|
if true && (true || let 0 = 0) {}
|
||||||
@ -210,7 +210,7 @@ fn nested_within_while_expr() {
|
|||||||
//~^ ERROR expected expression, found `let` statement
|
//~^ ERROR expected expression, found `let` statement
|
||||||
|
|
||||||
while true || let 0 = 0 {}
|
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) {}
|
while (true || let 0 = 0) {}
|
||||||
//~^ ERROR expected expression, found `let` statement
|
//~^ ERROR expected expression, found `let` statement
|
||||||
while true && (true || let 0 = 0) {}
|
while true && (true || let 0 = 0) {}
|
||||||
|
Loading…
Reference in New Issue
Block a user