diff --git a/compiler/rustc_parse/messages.ftl b/compiler/rustc_parse/messages.ftl index 66fa40e51d5..2c4bc7bb568 100644 --- a/compiler/rustc_parse/messages.ftl +++ b/compiler/rustc_parse/messages.ftl @@ -196,6 +196,7 @@ parse_expected_else_block = expected `{"{"}`, found {$first_tok} .suggestion = add an `if` if this is the condition of a chained `else if` statement parse_expected_expression_found_let = expected expression, found `let` statement + .note = only supported directly in conditions of `if` and `while` expressions .not_supported_or = `||` operators are not supported in let chain expressions .not_supported_parentheses = `let`s wrapped in parentheses are not supported in a context with let chains diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index 10b659d811a..5d3ec683552 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -392,6 +392,7 @@ pub(crate) struct IfExpressionMissingCondition { #[derive(Diagnostic)] #[diag(parse_expected_expression_found_let)] +#[note] pub(crate) struct ExpectedExpressionFoundLet { #[primary_span] pub span: Span, diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 43cd8fe55df..f4cee3a661e 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -2461,7 +2461,7 @@ impl<'a> Parser<'a> { let is_recovered = if !restrictions.contains(Restrictions::ALLOW_LET) { Some(self.sess.emit_err(errors::ExpectedExpressionFoundLet { span: self.token.span, - reason: ForbiddenLetReason::GenericForbidden, + reason: ForbiddenLetReason::OtherForbidden, })) } else { None @@ -3427,7 +3427,7 @@ impl<'a> Parser<'a> { #[derive(Clone, Copy, Subdiagnostic)] pub(crate) enum ForbiddenLetReason { /// `let` is not valid and the source environment is not important - GenericForbidden, + OtherForbidden, /// A let chain with the `||` operator #[note(parse_not_supported_or)] NotSupportedOr(#[primary_span] Span), @@ -3439,6 +3439,15 @@ pub(crate) enum ForbiddenLetReason { NotSupportedParentheses(#[primary_span] Span), } +/// Visitor to check for invalid/unstable use of `ExprKind::Let` that can't +/// easily be caught in parsing. For example: +/// +/// ```rust,ignore (example) +/// // Only know that the let isn't allowed once the `||` token is reached +/// if let Some(x) = y || true {} +/// // Only know that the let isn't allowed once the second `=` token is reached. +/// if let Some(x) = y && z = 1 {} +/// ``` struct CondChecker<'a> { parser: &'a Parser<'a>, forbid_let_reason: Option, @@ -3495,14 +3504,14 @@ impl MutVisitor for CondChecker<'_> { | ExprKind::Tup(_) | ExprKind::Paren(_) => { let forbid_let_reason = self.forbid_let_reason; - self.forbid_let_reason = Some(GenericForbidden); + self.forbid_let_reason = Some(OtherForbidden); noop_visit_expr(e, self); self.forbid_let_reason = forbid_let_reason; } ExprKind::Cast(ref mut op, _) | ExprKind::Type(ref mut op, _) => { let forbid_let_reason = self.forbid_let_reason; - self.forbid_let_reason = Some(GenericForbidden); + self.forbid_let_reason = Some(OtherForbidden); self.visit_expr(op); self.forbid_let_reason = forbid_let_reason; } diff --git a/tests/ui/expr/if/bad-if-let-suggestion.stderr b/tests/ui/expr/if/bad-if-let-suggestion.stderr index dc013155e81..20ac9ca76ba 100644 --- a/tests/ui/expr/if/bad-if-let-suggestion.stderr +++ b/tests/ui/expr/if/bad-if-let-suggestion.stderr @@ -3,6 +3,8 @@ error: expected expression, found `let` statement | LL | if let x = 1 && i = 2 {} | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error[E0425]: cannot find value `i` in this scope --> $DIR/bad-if-let-suggestion.rs:5:21 diff --git a/tests/ui/mir/issue-92893.stderr b/tests/ui/mir/issue-92893.stderr index 424b214c896..6c1a9dc0317 100644 --- a/tests/ui/mir/issue-92893.stderr +++ b/tests/ui/mir/issue-92893.stderr @@ -3,6 +3,8 @@ error: expected expression, found `let` statement | LL | struct Bug { | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: aborting due to previous error diff --git a/tests/ui/rfcs/rfc-2294-if-let-guard/feature-gate.stderr b/tests/ui/rfcs/rfc-2294-if-let-guard/feature-gate.stderr index a21ecae4eae..62534b555b2 100644 --- a/tests/ui/rfcs/rfc-2294-if-let-guard/feature-gate.stderr +++ b/tests/ui/rfcs/rfc-2294-if-let-guard/feature-gate.stderr @@ -4,6 +4,7 @@ error: expected expression, found `let` statement LL | () if (let 0 = 1) => {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/feature-gate.rs:10:16 | @@ -16,6 +17,7 @@ error: expected expression, found `let` statement LL | () if (((let 0 = 1))) => {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/feature-gate.rs:13:18 | @@ -28,6 +30,7 @@ error: expected expression, found `let` statement LL | () if (let 0 = 1) && true => {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/feature-gate.rs:24:16 | @@ -40,6 +43,7 @@ error: expected expression, found `let` statement LL | () if true && (let 0 = 1) => {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/feature-gate.rs:27:24 | @@ -52,6 +56,7 @@ error: expected expression, found `let` statement LL | () if (let 0 = 1) && (let 0 = 1) => {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/feature-gate.rs:30:16 | @@ -64,6 +69,7 @@ error: expected expression, found `let` statement LL | () if (let 0 = 1) && (let 0 = 1) => {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/feature-gate.rs:30:31 | @@ -76,6 +82,7 @@ error: expected expression, found `let` statement LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/feature-gate.rs:34:42 | @@ -88,6 +95,7 @@ error: expected expression, found `let` statement LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/feature-gate.rs:34:42 | @@ -100,6 +108,7 @@ error: expected expression, found `let` statement LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/feature-gate.rs:34:42 | @@ -111,12 +120,16 @@ error: expected expression, found `let` statement | LL | use_expr!((let 0 = 1 && 0 == 0)); | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/feature-gate.rs:62:16 | LL | use_expr!((let 0 = 1)); | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: no rules expected the token `let` --> $DIR/feature-gate.rs:70:15 diff --git a/tests/ui/rfcs/rfc-2294-if-let-guard/macro-expanded.stderr b/tests/ui/rfcs/rfc-2294-if-let-guard/macro-expanded.stderr index 41a20bf8ae1..00c1c303d2b 100644 --- a/tests/ui/rfcs/rfc-2294-if-let-guard/macro-expanded.stderr +++ b/tests/ui/rfcs/rfc-2294-if-let-guard/macro-expanded.stderr @@ -7,6 +7,7 @@ LL | ($e:expr) => { let Some(x) = $e } LL | () if m!(Some(5)) => {} | ----------- in this macro invocation | + = note: only supported directly in conditions of `if` and `while` expressions = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error diff --git a/tests/ui/rfcs/rfc-2294-if-let-guard/parens.stderr b/tests/ui/rfcs/rfc-2294-if-let-guard/parens.stderr index a6eced69c03..0c16d9c5442 100644 --- a/tests/ui/rfcs/rfc-2294-if-let-guard/parens.stderr +++ b/tests/ui/rfcs/rfc-2294-if-let-guard/parens.stderr @@ -4,6 +4,7 @@ error: expected expression, found `let` statement LL | () if (let 0 = 1) => {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/parens.rs:10:16 | @@ -16,6 +17,7 @@ error: expected expression, found `let` statement LL | () if (((let 0 = 1))) => {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/parens.rs:12:18 | @@ -28,6 +30,7 @@ error: expected expression, found `let` statement LL | () if (let 0 = 1) => {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/parens.rs:20:16 | @@ -40,6 +43,7 @@ error: expected expression, found `let` statement LL | () if (((let 0 = 1))) => {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/parens.rs:22:18 | diff --git a/tests/ui/rfcs/rfc-2497-if-let-chains/ast-validate-guards.stderr b/tests/ui/rfcs/rfc-2497-if-let-chains/ast-validate-guards.stderr index 20d0f86f212..4b85fdd5050 100644 --- a/tests/ui/rfcs/rfc-2497-if-let-chains/ast-validate-guards.stderr +++ b/tests/ui/rfcs/rfc-2497-if-let-chains/ast-validate-guards.stderr @@ -4,6 +4,7 @@ error: expected expression, found `let` statement 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 | diff --git a/tests/ui/rfcs/rfc-2497-if-let-chains/avoid-invalid-mir.stderr b/tests/ui/rfcs/rfc-2497-if-let-chains/avoid-invalid-mir.stderr index 8a8c5df9db9..3eaccde3b74 100644 --- a/tests/ui/rfcs/rfc-2497-if-let-chains/avoid-invalid-mir.stderr +++ b/tests/ui/rfcs/rfc-2497-if-let-chains/avoid-invalid-mir.stderr @@ -3,6 +3,8 @@ error: expected expression, found `let` statement | LL | !let y = 42; | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: aborting due to previous error diff --git a/tests/ui/rfcs/rfc-2497-if-let-chains/disallowed-positions-without-feature-gate.stderr b/tests/ui/rfcs/rfc-2497-if-let-chains/disallowed-positions-without-feature-gate.stderr index 218ca254d0f..31f389512ed 100644 --- a/tests/ui/rfcs/rfc-2497-if-let-chains/disallowed-positions-without-feature-gate.stderr +++ b/tests/ui/rfcs/rfc-2497-if-let-chains/disallowed-positions-without-feature-gate.stderr @@ -4,6 +4,7 @@ error: expected expression, found `let` statement LL | if (let 0 = 1) {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions-without-feature-gate.rs:11:9 | @@ -16,6 +17,7 @@ error: expected expression, found `let` statement LL | if (((let 0 = 1))) {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions-without-feature-gate.rs:14:11 | @@ -28,6 +30,7 @@ error: expected expression, found `let` statement LL | if (let 0 = 1) && true {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions-without-feature-gate.rs:17:9 | @@ -40,6 +43,7 @@ error: expected expression, found `let` statement LL | if true && (let 0 = 1) {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions-without-feature-gate.rs:20:17 | @@ -52,6 +56,7 @@ error: expected expression, found `let` statement LL | if (let 0 = 1) && (let 0 = 1) {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions-without-feature-gate.rs:23:9 | @@ -64,6 +69,7 @@ error: expected expression, found `let` statement LL | if (let 0 = 1) && (let 0 = 1) {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions-without-feature-gate.rs:23:24 | @@ -76,6 +82,7 @@ error: expected expression, found `let` statement LL | if (let 2 = 3 && let 3 = 4 && let 4 = 5) {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions-without-feature-gate.rs:27:9 | @@ -88,6 +95,7 @@ error: expected expression, found `let` statement LL | if (let 2 = 3 && let 3 = 4 && let 4 = 5) {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions-without-feature-gate.rs:27:9 | @@ -100,6 +108,7 @@ error: expected expression, found `let` statement LL | if (let 2 = 3 && let 3 = 4 && let 4 = 5) {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions-without-feature-gate.rs:27:9 | @@ -112,6 +121,7 @@ error: expected expression, found `let` statement LL | while (let 0 = 1) {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions-without-feature-gate.rs:34:12 | @@ -124,6 +134,7 @@ error: expected expression, found `let` statement LL | while (((let 0 = 1))) {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions-without-feature-gate.rs:37:14 | @@ -136,6 +147,7 @@ error: expected expression, found `let` statement LL | while (let 0 = 1) && true {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions-without-feature-gate.rs:40:12 | @@ -148,6 +160,7 @@ error: expected expression, found `let` statement LL | while true && (let 0 = 1) {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions-without-feature-gate.rs:43:20 | @@ -160,6 +173,7 @@ error: expected expression, found `let` statement LL | while (let 0 = 1) && (let 0 = 1) {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions-without-feature-gate.rs:46:12 | @@ -172,6 +186,7 @@ error: expected expression, found `let` statement LL | while (let 0 = 1) && (let 0 = 1) {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions-without-feature-gate.rs:46:27 | @@ -184,6 +199,7 @@ error: expected expression, found `let` statement LL | while (let 2 = 3 && let 3 = 4 && let 4 = 5) {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions-without-feature-gate.rs:50:12 | @@ -196,6 +212,7 @@ error: expected expression, found `let` statement LL | while (let 2 = 3 && let 3 = 4 && let 4 = 5) {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions-without-feature-gate.rs:50:12 | @@ -208,6 +225,7 @@ error: expected expression, found `let` statement LL | while (let 2 = 3 && let 3 = 4 && let 4 = 5) {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions-without-feature-gate.rs:50:12 | @@ -219,30 +237,40 @@ error: expected expression, found `let` statement | 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-without-feature-gate.rs:73:9 | 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-without-feature-gate.rs:75:9 | 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-without-feature-gate.rs:77:9 | 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-without-feature-gate.rs:85:9 | 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-without-feature-gate.rs:88:16 @@ -250,6 +278,7 @@ error: expected expression, found `let` statement 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-without-feature-gate.rs:88:13 | @@ -261,102 +290,136 @@ error: expected expression, found `let` statement | LL | if (true || let 0 = 0) {} | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:92:25 | LL | if true && (true || let 0 = 0) {} | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:94:25 | LL | if true || (true && let 0 = 0) {} | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:98:12 | LL | if x = let 0 = 0 {} | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:101:15 | LL | if true..(let 0 = 0) {} | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:104:11 | 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-without-feature-gate.rs:106:9 | 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-without-feature-gate.rs:110:8 | LL | if let Range { start: _, end: _ } = true..true && false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:113:8 | LL | if let Range { start: _, end: _ } = true..true || false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:119:8 | LL | if let Range { start: F, end } = F..|| true {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:125:8 | LL | if let Range { start: true, end } = t..&&false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:129:19 | LL | if let true = let true = true {} | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:134:12 | 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-without-feature-gate.rs:137:12 | 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-without-feature-gate.rs:139:12 | 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-without-feature-gate.rs:141:12 | 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-without-feature-gate.rs:149:12 | 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-without-feature-gate.rs:152:19 @@ -364,6 +427,7 @@ error: expected expression, found `let` statement 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-without-feature-gate.rs:152:16 | @@ -375,210 +439,280 @@ error: expected expression, found `let` statement | LL | while (true || let 0 = 0) {} | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:156:28 | LL | while true && (true || let 0 = 0) {} | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:158:28 | LL | while true || (true && let 0 = 0) {} | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:162:15 | LL | while x = let 0 = 0 {} | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:165:18 | LL | while true..(let 0 = 0) {} | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:168:14 | 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-without-feature-gate.rs:170:12 | 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-without-feature-gate.rs:174:11 | LL | while let Range { start: _, end: _ } = true..true && false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:177:11 | LL | while let Range { start: _, end: _ } = true..true || false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:183:11 | LL | while let Range { start: F, end } = F..|| true {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:189:11 | LL | while let Range { start: true, end } = t..&&false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:193:22 | LL | while let true = let true = true {} | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:208:6 | LL | &let 0 = 0; | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:211:6 | LL | !let 0 = 0; | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:213:6 | LL | *let 0 = 0; | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:215:6 | LL | -let 0 = 0; | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:217:13 | LL | let _ = let _ = 3; | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:225:6 | LL | (let 0 = 0)?; | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:228:13 | LL | true || let 0 = 0; | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:230:14 | LL | (true || let 0 = 0); | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:232:22 | LL | true && (true || let 0 = 0); | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:236:9 | LL | x = let 0 = 0; | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:239:12 | LL | true..(let 0 = 0); | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:241:8 | LL | ..(let 0 = 0); | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:243:6 | LL | (let 0 = 0)..; | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:246:6 | LL | (let Range { start: _, end: _ } = true..true || false); | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:250:6 | LL | (let true = let true = true); | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:250:17 | LL | (let true = let true = true); | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:256:25 | LL | let x = true && let y = 1; | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:262:19 | LL | [1, 2, 3][let _ = ()] | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:267:6 | LL | &let 0 = 0 | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:277:17 | LL | true && let 1 = 1 | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:282:17 | LL | true && let 1 = 1 | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:287:17 | LL | true && let 1 = 1 | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:298:17 | LL | true && let 1 = 1 | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expressions must be enclosed in braces to be used as const generic arguments --> $DIR/disallowed-positions-without-feature-gate.rs:298:9 @@ -597,6 +731,7 @@ error: expected expression, found `let` statement LL | if (let Some(a) = opt && true) { | ^^^^^^^^^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions-without-feature-gate.rs:307:9 | @@ -609,6 +744,7 @@ error: expected expression, found `let` statement LL | if (let Some(a) = opt) && true { | ^^^^^^^^^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions-without-feature-gate.rs:311:9 | @@ -621,6 +757,7 @@ error: expected expression, found `let` statement LL | if (let Some(a) = opt) && (let Some(b) = a) { | ^^^^^^^^^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions-without-feature-gate.rs:314:9 | @@ -633,6 +770,7 @@ error: expected expression, found `let` statement LL | if (let Some(a) = opt) && (let Some(b) = a) { | ^^^^^^^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions-without-feature-gate.rs:314:32 | @@ -645,6 +783,7 @@ error: expected expression, found `let` statement LL | if (let Some(a) = opt && (let Some(b) = a)) && b == 1 { | ^^^^^^^^^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions-without-feature-gate.rs:319:9 | @@ -657,6 +796,7 @@ error: expected expression, found `let` statement LL | if (let Some(a) = opt && (let Some(b) = a)) && b == 1 { | ^^^^^^^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions-without-feature-gate.rs:319:31 | @@ -669,6 +809,7 @@ error: expected expression, found `let` statement LL | if (let Some(a) = opt && (let Some(b) = a)) && true { | ^^^^^^^^^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions-without-feature-gate.rs:323:9 | @@ -681,6 +822,7 @@ error: expected expression, found `let` statement LL | if (let Some(a) = opt && (let Some(b) = a)) && true { | ^^^^^^^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions-without-feature-gate.rs:323:31 | @@ -693,6 +835,7 @@ error: expected expression, found `let` statement LL | if (let Some(a) = opt && (true)) && true { | ^^^^^^^^^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions-without-feature-gate.rs:327:9 | @@ -704,24 +847,32 @@ error: expected expression, found `let` statement | LL | let x = (true && let y = 1); | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:337:20 | LL | ([1, 2, 3][let _ = ()]) | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:63:16 | LL | use_expr!((let 0 = 1 && 0 == 0)); | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions-without-feature-gate.rs:65:16 | LL | use_expr!((let 0 = 1)); | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error[E0308]: mismatched types --> $DIR/disallowed-positions-without-feature-gate.rs:101:8 diff --git a/tests/ui/rfcs/rfc-2497-if-let-chains/disallowed-positions.stderr b/tests/ui/rfcs/rfc-2497-if-let-chains/disallowed-positions.stderr index ec7ff00425d..ab58abf4d46 100644 --- a/tests/ui/rfcs/rfc-2497-if-let-chains/disallowed-positions.stderr +++ b/tests/ui/rfcs/rfc-2497-if-let-chains/disallowed-positions.stderr @@ -4,6 +4,7 @@ error: expected expression, found `let` statement LL | if (let 0 = 1) {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions.rs:29:9 | @@ -16,6 +17,7 @@ error: expected expression, found `let` statement LL | if (((let 0 = 1))) {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions.rs:32:11 | @@ -28,6 +30,7 @@ error: expected expression, found `let` statement LL | if (let 0 = 1) && true {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions.rs:35:9 | @@ -40,6 +43,7 @@ error: expected expression, found `let` statement LL | if true && (let 0 = 1) {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions.rs:38:17 | @@ -52,6 +56,7 @@ error: expected expression, found `let` statement LL | if (let 0 = 1) && (let 0 = 1) {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions.rs:41:9 | @@ -64,6 +69,7 @@ error: expected expression, found `let` statement LL | if (let 0 = 1) && (let 0 = 1) {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions.rs:41:24 | @@ -76,6 +82,7 @@ error: expected expression, found `let` statement LL | if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions.rs:45:35 | @@ -88,6 +95,7 @@ error: expected expression, found `let` statement LL | if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions.rs:45:35 | @@ -100,6 +108,7 @@ error: expected expression, found `let` statement LL | if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions.rs:45:35 | @@ -112,6 +121,7 @@ error: expected expression, found `let` statement LL | while (let 0 = 1) {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions.rs:52:12 | @@ -124,6 +134,7 @@ error: expected expression, found `let` statement LL | while (((let 0 = 1))) {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions.rs:55:14 | @@ -136,6 +147,7 @@ error: expected expression, found `let` statement LL | while (let 0 = 1) && true {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions.rs:58:12 | @@ -148,6 +160,7 @@ error: expected expression, found `let` statement LL | while true && (let 0 = 1) {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions.rs:61:20 | @@ -160,6 +173,7 @@ error: expected expression, found `let` statement LL | while (let 0 = 1) && (let 0 = 1) {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions.rs:64:12 | @@ -172,6 +186,7 @@ error: expected expression, found `let` statement LL | while (let 0 = 1) && (let 0 = 1) {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions.rs:64:27 | @@ -184,6 +199,7 @@ error: expected expression, found `let` statement LL | while let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions.rs:68:38 | @@ -196,6 +212,7 @@ error: expected expression, found `let` statement LL | while let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions.rs:68:38 | @@ -208,6 +225,7 @@ error: expected expression, found `let` statement LL | while let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) {} | ^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions.rs:68:38 | @@ -219,30 +237,40 @@ error: expected expression, found `let` statement | 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:91:9 | 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:93:9 | 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:95:9 | 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:103:9 | 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:106:16 @@ -250,6 +278,7 @@ error: expected expression, found `let` statement 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:106:13 | @@ -261,102 +290,136 @@ error: expected expression, found `let` statement | LL | if (true || let 0 = 0) {} | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:110:25 | LL | if true && (true || let 0 = 0) {} | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:112:25 | LL | if true || (true && let 0 = 0) {} | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:116:12 | LL | if x = let 0 = 0 {} | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:119:15 | LL | if true..(let 0 = 0) {} | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:122:11 | 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:124:9 | 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:128:8 | LL | if let Range { start: _, end: _ } = true..true && false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:131:8 | LL | if let Range { start: _, end: _ } = true..true || false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:137:8 | LL | if let Range { start: F, end } = F..|| true {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:143:8 | LL | if let Range { start: true, end } = t..&&false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:147:19 | LL | if let true = let true = true {} | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:152:12 | 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:155:12 | 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:157:12 | 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:159:12 | 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:167:12 | 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:170:19 @@ -364,6 +427,7 @@ error: expected expression, found `let` statement 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:170:16 | @@ -375,204 +439,272 @@ error: expected expression, found `let` statement | LL | while (true || let 0 = 0) {} | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:174:28 | LL | while true && (true || let 0 = 0) {} | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:176:28 | LL | while true || (true && let 0 = 0) {} | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:180:15 | LL | while x = let 0 = 0 {} | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:183:18 | LL | while true..(let 0 = 0) {} | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:186:14 | 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:188:12 | 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:192:11 | LL | while let Range { start: _, end: _ } = true..true && false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:195:11 | LL | while let Range { start: _, end: _ } = true..true || false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:201:11 | LL | while let Range { start: F, end } = F..|| true {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:207:11 | LL | while let Range { start: true, end } = t..&&false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:211:22 | LL | while let true = let true = true {} | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:226:6 | LL | &let 0 = 0; | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:229:6 | LL | !let 0 = 0; | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:231:6 | LL | *let 0 = 0; | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:233:6 | LL | -let 0 = 0; | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:241:6 | LL | (let 0 = 0)?; | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:244:13 | LL | true || let 0 = 0; | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:246:14 | LL | (true || let 0 = 0); | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:248:22 | LL | true && (true || let 0 = 0); | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:252:9 | LL | x = let 0 = 0; | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:255:12 | LL | true..(let 0 = 0); | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:257:8 | LL | ..(let 0 = 0); | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:259:6 | LL | (let 0 = 0)..; | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:262:6 | LL | (let Range { start: _, end: _ } = true..true || false); | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:266:6 | LL | (let true = let true = true); | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:266:17 | LL | (let true = let true = true); | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:272:25 | LL | let x = true && let y = 1; | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:278:19 | LL | [1, 2, 3][let _ = ()] | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:283:6 | LL | &let 0 = 0 | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:293:17 | LL | true && let 1 = 1 | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:298:17 | LL | true && let 1 = 1 | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:303:17 | LL | true && let 1 = 1 | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:314:17 | LL | true && let 1 = 1 | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expressions must be enclosed in braces to be used as const generic arguments --> $DIR/disallowed-positions.rs:314:9 @@ -591,6 +723,7 @@ error: expected expression, found `let` statement LL | if (let Some(a) = opt && true) { | ^^^^^^^^^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions.rs:323:9 | @@ -603,6 +736,7 @@ error: expected expression, found `let` statement LL | if (let Some(a) = opt) && true { | ^^^^^^^^^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions.rs:327:9 | @@ -615,6 +749,7 @@ error: expected expression, found `let` statement LL | if (let Some(a) = opt) && (let Some(b) = a) { | ^^^^^^^^^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions.rs:330:9 | @@ -627,6 +762,7 @@ error: expected expression, found `let` statement LL | if (let Some(a) = opt) && (let Some(b) = a) { | ^^^^^^^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions.rs:330:32 | @@ -639,6 +775,7 @@ error: expected expression, found `let` statement LL | if (let Some(a) = opt && (let Some(b) = a)) && b == 1 { | ^^^^^^^^^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions.rs:337:9 | @@ -651,6 +788,7 @@ error: expected expression, found `let` statement LL | if (let Some(a) = opt && (let Some(b) = a)) && b == 1 { | ^^^^^^^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions.rs:337:31 | @@ -663,6 +801,7 @@ error: expected expression, found `let` statement LL | if (let Some(a) = opt && (let Some(b) = a)) && true { | ^^^^^^^^^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions.rs:341:9 | @@ -675,6 +814,7 @@ error: expected expression, found `let` statement LL | if (let Some(a) = opt && (let Some(b) = a)) && true { | ^^^^^^^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions.rs:341:31 | @@ -687,6 +827,7 @@ error: expected expression, found `let` statement LL | if (let Some(a) = opt && (true)) && true { | ^^^^^^^^^^^^^^^^^ | + = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains --> $DIR/disallowed-positions.rs:345:9 | @@ -698,24 +839,32 @@ error: expected expression, found `let` statement | LL | let x = (true && let y = 1); | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:366:20 | LL | ([1, 2, 3][let _ = ()]) | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:81:16 | LL | use_expr!((let 0 = 1 && 0 == 0)); | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:83:16 | LL | use_expr!((let 0 = 1)); | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error[E0308]: mismatched types --> $DIR/disallowed-positions.rs:119:8 diff --git a/tests/ui/rfcs/rfc-2497-if-let-chains/ensure-that-let-else-does-not-interact-with-let-chains.stderr b/tests/ui/rfcs/rfc-2497-if-let-chains/ensure-that-let-else-does-not-interact-with-let-chains.stderr index 56c1d865062..0442f1218b1 100644 --- a/tests/ui/rfcs/rfc-2497-if-let-chains/ensure-that-let-else-does-not-interact-with-let-chains.stderr +++ b/tests/ui/rfcs/rfc-2497-if-let-chains/ensure-that-let-else-does-not-interact-with-let-chains.stderr @@ -14,6 +14,8 @@ error: expected expression, found `let` statement | LL | let Some(n) = opt && let another = n else { | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: a `&&` expression cannot be directly assigned in `let...else` --> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:15:19 diff --git a/tests/ui/rfcs/rfc-2497-if-let-chains/feature-gate.stderr b/tests/ui/rfcs/rfc-2497-if-let-chains/feature-gate.stderr index c648c864a5e..6f74736755e 100644 --- a/tests/ui/rfcs/rfc-2497-if-let-chains/feature-gate.stderr +++ b/tests/ui/rfcs/rfc-2497-if-let-chains/feature-gate.stderr @@ -3,12 +3,16 @@ error: expected expression, found `let` statement | LL | #[cfg(FALSE)] (let 0 = 1); | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/feature-gate.rs:45:17 | LL | noop_expr!((let 0 = 1)); | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: no rules expected the token `let` --> $DIR/feature-gate.rs:56:15 diff --git a/tests/ui/rfcs/rfc-2497-if-let-chains/invalid-let-in-a-valid-let-context.stderr b/tests/ui/rfcs/rfc-2497-if-let-chains/invalid-let-in-a-valid-let-context.stderr index 160559510f1..247fad2e992 100644 --- a/tests/ui/rfcs/rfc-2497-if-let-chains/invalid-let-in-a-valid-let-context.stderr +++ b/tests/ui/rfcs/rfc-2497-if-let-chains/invalid-let-in-a-valid-let-context.stderr @@ -3,48 +3,64 @@ error: expected expression, found `let` statement | LL | let _ = &&let Some(x) = Some(42); | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/invalid-let-in-a-valid-let-context.rs:13:47 | LL | if let Some(elem) = _opt && [1, 2, 3][let _ = &&let Some(x) = Some(42)] = 1 { | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/invalid-let-in-a-valid-let-context.rs:13:57 | LL | if let Some(elem) = _opt && [1, 2, 3][let _ = &&let Some(x) = Some(42)] = 1 { | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/invalid-let-in-a-valid-let-context.rs:13:12 | LL | if let Some(elem) = _opt && [1, 2, 3][let _ = &&let Some(x) = Some(42)] = 1 { | ^^^^^^^^^^^^^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/invalid-let-in-a-valid-let-context.rs:24:23 | LL | [1, 2, 3][let _ = ()]; | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/invalid-let-in-a-valid-let-context.rs:33:47 | LL | if let Some(elem) = _opt && [1, 2, 3][let _ = ()] = 1 { | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/invalid-let-in-a-valid-let-context.rs:33:12 | LL | if let Some(elem) = _opt && [1, 2, 3][let _ = ()] = 1 { | ^^^^^^^^^^^^^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/invalid-let-in-a-valid-let-context.rs:42:21 | LL | let x = let y = 1; | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: aborting due to 8 previous errors