From 333388fd3c9fa03362a3c2a2675ab521c4ddb1ff Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Fri, 8 Sep 2023 10:14:36 +0000 Subject: Move let expression checking to parsing There was an incomplete version of the check in parsing and a second version in AST validation. This meant that some, but not all, invalid uses were allowed inside macros/disabled cfgs. It also means that later passes have a hard time knowing when the let expression is in a valid location, sometimes causing ICEs. - Add a field to ExprKind::Let in AST/HIR to mark whether it's in a valid location. - Suppress later errors and MIR construction for invalid let expressions. --- compiler/rustc_parse/src/parser/expr.rs | 369 +++++++++++++++++++++----------- compiler/rustc_parse/src/parser/mod.rs | 1 + 2 files changed, 249 insertions(+), 121 deletions(-) (limited to 'compiler/rustc_parse/src/parser') diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 5898c6565e6..82701a8b5d5 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -8,6 +8,7 @@ use super::{ use crate::errors; use crate::maybe_recover_from_interpolated_ty_qpath; +use ast::mut_visit::{noop_visit_expr, MutVisitor}; use ast::{Path, PathSegment}; use core::mem; use rustc_ast::ptr::P; @@ -27,6 +28,7 @@ use rustc_errors::{ AddToDiagnostic, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, IntoDiagnostic, PResult, StashKey, }; +use rustc_macros::Subdiagnostic; use rustc_session::errors::{report_lit_error, ExprParenthesesNeeded}; use rustc_session::lint::builtin::BREAK_WITH_LABEL_AND_LOOP; use rustc_session::lint::BuiltinLintDiagnostics; @@ -122,8 +124,8 @@ impl<'a> Parser<'a> { self.parse_expr().map(|value| AnonConst { id: DUMMY_NODE_ID, value }) } - fn parse_expr_catch_underscore(&mut self) -> PResult<'a, P> { - match self.parse_expr() { + fn parse_expr_catch_underscore(&mut self, restrictions: Restrictions) -> PResult<'a, P> { + match self.parse_expr_res(restrictions, None) { Ok(expr) => Ok(expr), Err(mut err) => match self.token.ident() { Some((Ident { name: kw::Underscore, .. }, false)) @@ -141,7 +143,8 @@ impl<'a> Parser<'a> { /// Parses a sequence of expressions delimited by parentheses. fn parse_expr_paren_seq(&mut self) -> PResult<'a, ThinVec>> { - self.parse_paren_comma_seq(|p| p.parse_expr_catch_underscore()).map(|(r, _)| r) + self.parse_paren_comma_seq(|p| p.parse_expr_catch_underscore(Restrictions::empty())) + .map(|(r, _)| r) } /// Parses an expression, subject to the given restrictions. @@ -1345,110 +1348,113 @@ impl<'a> Parser<'a> { // Outer attributes are already parsed and will be // added to the return value after the fact. - // Note: when adding new syntax here, don't forget to adjust `TokenKind::can_begin_expr()`. - let lo = self.token.span; - if let token::Literal(_) = self.token.kind { - // This match arm is a special-case of the `_` match arm below and - // could be removed without changing functionality, but it's faster - // to have it here, especially for programs with large constants. - self.parse_expr_lit() - } else if self.check(&token::OpenDelim(Delimiter::Parenthesis)) { - self.parse_expr_tuple_parens() - } else if self.check(&token::OpenDelim(Delimiter::Brace)) { - self.parse_expr_block(None, lo, BlockCheckMode::Default) - } else if self.check(&token::BinOp(token::Or)) || self.check(&token::OrOr) { - self.parse_expr_closure().map_err(|mut err| { - // If the input is something like `if a { 1 } else { 2 } | if a { 3 } else { 4 }` - // then suggest parens around the lhs. - if let Some(sp) = self.sess.ambiguous_block_expr_parse.borrow().get(&lo) { - err.subdiagnostic(ExprParenthesesNeeded::surrounding(*sp)); + let restrictions = self.restrictions; + self.with_res(restrictions - Restrictions::ALLOW_LET, |this| { + // Note: when adding new syntax here, don't forget to adjust `TokenKind::can_begin_expr()`. + let lo = this.token.span; + if let token::Literal(_) = this.token.kind { + // This match arm is a special-case of the `_` match arm below and + // could be removed without changing functionality, but it's faster + // to have it here, especially for programs with large constants. + this.parse_expr_lit() + } else if this.check(&token::OpenDelim(Delimiter::Parenthesis)) { + this.parse_expr_tuple_parens(restrictions) + } else if this.check(&token::OpenDelim(Delimiter::Brace)) { + this.parse_expr_block(None, lo, BlockCheckMode::Default) + } else if this.check(&token::BinOp(token::Or)) || this.check(&token::OrOr) { + this.parse_expr_closure().map_err(|mut err| { + // If the input is something like `if a { 1 } else { 2 } | if a { 3 } else { 4 }` + // then suggest parens around the lhs. + if let Some(sp) = this.sess.ambiguous_block_expr_parse.borrow().get(&lo) { + err.subdiagnostic(ExprParenthesesNeeded::surrounding(*sp)); + } + err + }) + } else if this.check(&token::OpenDelim(Delimiter::Bracket)) { + this.parse_expr_array_or_repeat(Delimiter::Bracket) + } else if this.is_builtin() { + this.parse_expr_builtin() + } else if this.check_path() { + this.parse_expr_path_start() + } else if this.check_keyword(kw::Move) + || this.check_keyword(kw::Static) + || this.check_const_closure() + { + this.parse_expr_closure() + } else if this.eat_keyword(kw::If) { + this.parse_expr_if() + } else if this.check_keyword(kw::For) { + if this.choose_generics_over_qpath(1) { + this.parse_expr_closure() + } else { + assert!(this.eat_keyword(kw::For)); + this.parse_expr_for(None, this.prev_token.span) } - err - }) - } else if self.check(&token::OpenDelim(Delimiter::Bracket)) { - self.parse_expr_array_or_repeat(Delimiter::Bracket) - } else if self.is_builtin() { - self.parse_expr_builtin() - } else if self.check_path() { - self.parse_expr_path_start() - } else if self.check_keyword(kw::Move) - || self.check_keyword(kw::Static) - || self.check_const_closure() - { - self.parse_expr_closure() - } else if self.eat_keyword(kw::If) { - self.parse_expr_if() - } else if self.check_keyword(kw::For) { - if self.choose_generics_over_qpath(1) { - self.parse_expr_closure() - } else { - assert!(self.eat_keyword(kw::For)); - self.parse_expr_for(None, self.prev_token.span) - } - } else if self.eat_keyword(kw::While) { - self.parse_expr_while(None, self.prev_token.span) - } else if let Some(label) = self.eat_label() { - self.parse_expr_labeled(label, true) - } else if self.eat_keyword(kw::Loop) { - let sp = self.prev_token.span; - self.parse_expr_loop(None, self.prev_token.span).map_err(|mut err| { - err.span_label(sp, "while parsing this `loop` expression"); - err - }) - } else if self.eat_keyword(kw::Match) { - let match_sp = self.prev_token.span; - self.parse_expr_match().map_err(|mut err| { - err.span_label(match_sp, "while parsing this `match` expression"); - err - }) - } else if self.eat_keyword(kw::Unsafe) { - let sp = self.prev_token.span; - self.parse_expr_block(None, lo, BlockCheckMode::Unsafe(ast::UserProvided)).map_err( - |mut err| { - err.span_label(sp, "while parsing this `unsafe` expression"); + } else if this.eat_keyword(kw::While) { + this.parse_expr_while(None, this.prev_token.span) + } else if let Some(label) = this.eat_label() { + this.parse_expr_labeled(label, true) + } else if this.eat_keyword(kw::Loop) { + let sp = this.prev_token.span; + this.parse_expr_loop(None, this.prev_token.span).map_err(|mut err| { + err.span_label(sp, "while parsing this `loop` expression"); err - }, - ) - } else if self.check_inline_const(0) { - self.parse_const_block(lo.to(self.token.span), false) - } else if self.may_recover() && self.is_do_catch_block() { - self.recover_do_catch() - } else if self.is_try_block() { - self.expect_keyword(kw::Try)?; - self.parse_try_block(lo) - } else if self.eat_keyword(kw::Return) { - self.parse_expr_return() - } else if self.eat_keyword(kw::Continue) { - self.parse_expr_continue(lo) - } else if self.eat_keyword(kw::Break) { - self.parse_expr_break() - } else if self.eat_keyword(kw::Yield) { - self.parse_expr_yield() - } else if self.is_do_yeet() { - self.parse_expr_yeet() - } else if self.eat_keyword(kw::Become) { - self.parse_expr_become() - } else if self.check_keyword(kw::Let) { - self.parse_expr_let() - } else if self.eat_keyword(kw::Underscore) { - Ok(self.mk_expr(self.prev_token.span, ExprKind::Underscore)) - } else if self.token.uninterpolated_span().at_least_rust_2018() { - // `Span:.at_least_rust_2018()` is somewhat expensive; don't get it repeatedly. - if self.check_keyword(kw::Async) { - if self.is_async_block() { - // Check for `async {` and `async move {`. - self.parse_async_block() + }) + } else if this.eat_keyword(kw::Match) { + let match_sp = this.prev_token.span; + this.parse_expr_match().map_err(|mut err| { + err.span_label(match_sp, "while parsing this `match` expression"); + err + }) + } else if this.eat_keyword(kw::Unsafe) { + let sp = this.prev_token.span; + this.parse_expr_block(None, lo, BlockCheckMode::Unsafe(ast::UserProvided)).map_err( + |mut err| { + err.span_label(sp, "while parsing this `unsafe` expression"); + err + }, + ) + } else if this.check_inline_const(0) { + this.parse_const_block(lo.to(this.token.span), false) + } else if this.may_recover() && this.is_do_catch_block() { + this.recover_do_catch() + } else if this.is_try_block() { + this.expect_keyword(kw::Try)?; + this.parse_try_block(lo) + } else if this.eat_keyword(kw::Return) { + this.parse_expr_return() + } else if this.eat_keyword(kw::Continue) { + this.parse_expr_continue(lo) + } else if this.eat_keyword(kw::Break) { + this.parse_expr_break() + } else if this.eat_keyword(kw::Yield) { + this.parse_expr_yield() + } else if this.is_do_yeet() { + this.parse_expr_yeet() + } else if this.eat_keyword(kw::Become) { + this.parse_expr_become() + } else if this.check_keyword(kw::Let) { + this.parse_expr_let(restrictions) + } else if this.eat_keyword(kw::Underscore) { + Ok(this.mk_expr(this.prev_token.span, ExprKind::Underscore)) + } else if this.token.uninterpolated_span().at_least_rust_2018() { + // `Span:.at_least_rust_2018()` is somewhat expensive; don't get it repeatedly. + if this.check_keyword(kw::Async) { + if this.is_async_block() { + // Check for `async {` and `async move {`. + this.parse_async_block() + } else { + this.parse_expr_closure() + } + } else if this.eat_keyword(kw::Await) { + this.recover_incorrect_await_syntax(lo, this.prev_token.span) } else { - self.parse_expr_closure() + this.parse_expr_lit() } - } else if self.eat_keyword(kw::Await) { - self.recover_incorrect_await_syntax(lo, self.prev_token.span) } else { - self.parse_expr_lit() + this.parse_expr_lit() } - } else { - self.parse_expr_lit() - } + }) } fn parse_expr_lit(&mut self) -> PResult<'a, P> { @@ -1462,13 +1468,13 @@ impl<'a> Parser<'a> { } } - fn parse_expr_tuple_parens(&mut self) -> PResult<'a, P> { + fn parse_expr_tuple_parens(&mut self, restrictions: Restrictions) -> PResult<'a, P> { let lo = self.token.span; self.expect(&token::OpenDelim(Delimiter::Parenthesis))?; let (es, trailing_comma) = match self.parse_seq_to_end( &token::CloseDelim(Delimiter::Parenthesis), SeqSep::trailing_allowed(token::Comma), - |p| p.parse_expr_catch_underscore(), + |p| p.parse_expr_catch_underscore(restrictions.intersection(Restrictions::ALLOW_LET)), ) { Ok(x) => x, Err(err) => { @@ -2231,7 +2237,8 @@ impl<'a> Parser<'a> { let decl_hi = self.prev_token.span; let mut body = match fn_decl.output { FnRetTy::Default(_) => { - let restrictions = self.restrictions - Restrictions::STMT_EXPR; + let restrictions = + self.restrictions - Restrictions::STMT_EXPR - Restrictions::ALLOW_LET; self.parse_expr_res(restrictions, None)? } _ => { @@ -2436,10 +2443,12 @@ impl<'a> Parser<'a> { /// Parses the condition of a `if` or `while` expression. fn parse_expr_cond(&mut self) -> PResult<'a, P> { - let cond = + let mut cond = self.parse_expr_res(Restrictions::NO_STRUCT_LITERAL | Restrictions::ALLOW_LET, None)?; - if let ExprKind::Let(..) = cond.kind { + CondChecker { parser: self, forbid_let_reason: None }.visit_expr(&mut cond); + + if let ExprKind::Let(_, _, _, None) = cond.kind { // Remove the last feature gating of a `let` expression since it's stable. self.sess.gated_spans.ungate_last(sym::let_chains, cond.span); } @@ -2448,18 +2457,15 @@ impl<'a> Parser<'a> { } /// Parses a `let $pat = $expr` pseudo-expression. - fn parse_expr_let(&mut self) -> PResult<'a, P> { - // This is a *approximate* heuristic that detects if `let` chains are - // being parsed in the right position. It's approximate because it - // doesn't deny all invalid `let` expressions, just completely wrong usages. - let not_in_chain = !matches!( - self.prev_token.kind, - TokenKind::AndAnd | TokenKind::Ident(kw::If, _) | TokenKind::Ident(kw::While, _) - ); - if !self.restrictions.contains(Restrictions::ALLOW_LET) || not_in_chain { - self.sess.emit_err(errors::ExpectedExpressionFoundLet { span: self.token.span }); - } - + fn parse_expr_let(&mut self, restrictions: Restrictions) -> PResult<'a, P> { + let is_recovered = if !restrictions.contains(Restrictions::ALLOW_LET) { + Some(self.sess.emit_err(errors::ExpectedExpressionFoundLet { + span: self.token.span, + reason: ForbiddenLetReason::GenericForbidden, + })) + } else { + None + }; self.bump(); // Eat `let` token let lo = self.prev_token.span; let pat = self.parse_pat_allow_top_alt( @@ -2479,8 +2485,10 @@ impl<'a> Parser<'a> { } let expr = self.parse_expr_assoc_with(1 + prec_let_scrutinee_needs_par(), None.into())?; let span = lo.to(expr.span); - self.sess.gated_spans.gate(sym::let_chains, span); - Ok(self.mk_expr(span, ExprKind::Let(pat, expr, span))) + if is_recovered.is_none() { + self.sess.gated_spans.gate(sym::let_chains, span); + } + Ok(self.mk_expr(span, ExprKind::Let(pat, expr, span, is_recovered))) } /// Parses an `else { ... }` expression (`else` token already eaten). @@ -2829,7 +2837,10 @@ impl<'a> Parser<'a> { )?; let guard = if this.eat_keyword(kw::If) { let if_span = this.prev_token.span; - let cond = this.parse_expr_res(Restrictions::ALLOW_LET, None)?; + let mut cond = this.parse_expr_res(Restrictions::ALLOW_LET, None)?; + + CondChecker { parser: this, forbid_let_reason: None }.visit_expr(&mut cond); + let (has_let_expr, does_not_have_bin_op) = check_let_expr(&cond); if has_let_expr { if does_not_have_bin_op { @@ -3414,3 +3425,119 @@ impl<'a> Parser<'a> { }) } } + +/// Used to forbid `let` expressions in certain syntactic locations. +#[derive(Clone, Copy, Subdiagnostic)] +pub(crate) enum ForbiddenLetReason { + /// `let` is not valid and the source environment is not important + GenericForbidden, + /// A let chain with the `||` operator + #[note(parse_not_supported_or)] + NotSupportedOr(#[primary_span] Span), + /// A let chain with invalid parentheses + /// + /// For example, `let 1 = 1 && (expr && expr)` is allowed + /// but `(let 1 = 1 && (let 1 = 1 && (let 1 = 1))) && let a = 1` is not + #[note(parse_not_supported_parentheses)] + NotSupportedParentheses(#[primary_span] Span), +} + +struct CondChecker<'a> { + parser: &'a Parser<'a>, + forbid_let_reason: Option, +} + +impl MutVisitor for CondChecker<'_> { + fn visit_expr(&mut self, e: &mut P) { + use ForbiddenLetReason::*; + + let span = e.span; + match e.kind { + ExprKind::Let(_, _, _, ref mut is_recovered @ None) => { + if let Some(reason) = self.forbid_let_reason { + *is_recovered = Some( + self.parser + .sess + .emit_err(errors::ExpectedExpressionFoundLet { span, reason }), + ); + } + } + ExprKind::Binary(Spanned { node: BinOpKind::And, .. }, _, _) => { + noop_visit_expr(e, self); + } + ExprKind::Binary(Spanned { node: BinOpKind::Or, span: or_span }, _, _) + if let None | Some(NotSupportedOr(_)) = self.forbid_let_reason => + { + let forbid_let_reason = self.forbid_let_reason; + self.forbid_let_reason = Some(NotSupportedOr(or_span)); + noop_visit_expr(e, self); + self.forbid_let_reason = forbid_let_reason; + } + ExprKind::Paren(ref inner) + if let None | Some(NotSupportedParentheses(_)) = self.forbid_let_reason => + { + let forbid_let_reason = self.forbid_let_reason; + self.forbid_let_reason = Some(NotSupportedParentheses(inner.span)); + noop_visit_expr(e, self); + self.forbid_let_reason = forbid_let_reason; + } + ExprKind::Unary(_, _) + | ExprKind::Await(_, _) + | ExprKind::Assign(_, _, _) + | ExprKind::AssignOp(_, _, _) + | ExprKind::Range(_, _, _) + | ExprKind::Try(_) + | ExprKind::AddrOf(_, _, _) + | ExprKind::Binary(_, _, _) + | ExprKind::Field(_, _) + | ExprKind::Index(_, _, _) + | ExprKind::Call(_, _) + | ExprKind::MethodCall(_) + | ExprKind::Tup(_) + | ExprKind::Paren(_) => { + let forbid_let_reason = self.forbid_let_reason; + self.forbid_let_reason = Some(GenericForbidden); + 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.visit_expr(op); + self.forbid_let_reason = forbid_let_reason; + } + ExprKind::Let(_, _, _, Some(_)) + | ExprKind::Array(_) + | ExprKind::ConstBlock(_) + | ExprKind::Lit(_) + | ExprKind::If(_, _, _) + | ExprKind::While(_, _, _) + | ExprKind::ForLoop(_, _, _, _) + | ExprKind::Loop(_, _, _) + | ExprKind::Match(_, _) + | ExprKind::Closure(_) + | ExprKind::Block(_, _) + | ExprKind::Async(_, _) + | ExprKind::TryBlock(_) + | ExprKind::Underscore + | ExprKind::Path(_, _) + | ExprKind::Break(_, _) + | ExprKind::Continue(_) + | ExprKind::Ret(_) + | ExprKind::InlineAsm(_) + | ExprKind::OffsetOf(_, _) + | ExprKind::MacCall(_) + | ExprKind::Struct(_) + | ExprKind::Repeat(_, _) + | ExprKind::Yield(_) + | ExprKind::Yeet(_) + | ExprKind::Become(_) + | ExprKind::IncludedBytes(_) + | ExprKind::FormatArgs(_) + | ExprKind::Err => { + // These would forbid any let expressions they contain already. + } + } + } +} diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 77c59bb3881..e84d8f5b358 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -13,6 +13,7 @@ mod ty; use crate::lexer::UnmatchedDelim; pub use attr_wrapper::AttrWrapper; pub use diagnostics::AttemptLocalParseRecovery; +pub(crate) use expr::ForbiddenLetReason; pub(crate) use item::FnParseMode; pub use pat::{CommaRecoveryMode, RecoverColon, RecoverComma}; pub use path::PathStyle; -- cgit 1.4.1-3-g733a5 From b011a0a13b4354080b3add0bb3f4445ddb8fd13b Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Mon, 11 Sep 2023 16:16:59 +0000 Subject: Reduce double errors for invalid let expressions Previously some invalid let expressions would result in both a feature error and a parsing error. Avoid this and ensure that we only emit the parsing error when this happens. --- compiler/rustc_parse/src/parser/expr.rs | 5 +- tests/ui/expr/if/bad-if-let-suggestion.rs | 1 - tests/ui/expr/if/bad-if-let-suggestion.stderr | 21 +- .../ui/rfcs/rfc-2294-if-let-guard/feature-gate.rs | 9 - .../rfcs/rfc-2294-if-let-guard/feature-gate.stderr | 143 +--- .../disallowed-positions-without-feature-gate.rs | 340 ++++++++ ...isallowed-positions-without-feature-gate.stderr | 870 +++++++++++++++++++++ 7 files changed, 1249 insertions(+), 140 deletions(-) create mode 100644 tests/ui/rfcs/rfc-2497-if-let-chains/disallowed-positions-without-feature-gate.rs create mode 100644 tests/ui/rfcs/rfc-2497-if-let-chains/disallowed-positions-without-feature-gate.stderr (limited to 'compiler/rustc_parse/src/parser') diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 82701a8b5d5..43cd8fe55df 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -2485,9 +2485,6 @@ impl<'a> Parser<'a> { } let expr = self.parse_expr_assoc_with(1 + prec_let_scrutinee_needs_par(), None.into())?; let span = lo.to(expr.span); - if is_recovered.is_none() { - self.sess.gated_spans.gate(sym::let_chains, span); - } Ok(self.mk_expr(span, ExprKind::Let(pat, expr, span, is_recovered))) } @@ -3460,6 +3457,8 @@ impl MutVisitor for CondChecker<'_> { .sess .emit_err(errors::ExpectedExpressionFoundLet { span, reason }), ); + } else { + self.parser.sess.gated_spans.gate(sym::let_chains, span); } } ExprKind::Binary(Spanned { node: BinOpKind::And, .. }, _, _) => { diff --git a/tests/ui/expr/if/bad-if-let-suggestion.rs b/tests/ui/expr/if/bad-if-let-suggestion.rs index 1ff9f3fa3d0..99d584ac7a5 100644 --- a/tests/ui/expr/if/bad-if-let-suggestion.rs +++ b/tests/ui/expr/if/bad-if-let-suggestion.rs @@ -4,7 +4,6 @@ fn a() { if let x = 1 && i = 2 {} //~^ ERROR cannot find value `i` in this scope - //~| ERROR `let` expressions in this position are unstable //~| ERROR mismatched types //~| ERROR expected expression, found `let` statement } diff --git a/tests/ui/expr/if/bad-if-let-suggestion.stderr b/tests/ui/expr/if/bad-if-let-suggestion.stderr index a2367c59040..dc013155e81 100644 --- a/tests/ui/expr/if/bad-if-let-suggestion.stderr +++ b/tests/ui/expr/if/bad-if-let-suggestion.stderr @@ -11,7 +11,7 @@ LL | if let x = 1 && i = 2 {} | ^ not found in this scope error[E0425]: cannot find value `i` in this scope - --> $DIR/bad-if-let-suggestion.rs:13:9 + --> $DIR/bad-if-let-suggestion.rs:12:9 | LL | fn a() { | ------ similarly named function `a` defined here @@ -20,7 +20,7 @@ LL | if (i + j) = i {} | ^ help: a function with a similar name exists: `a` error[E0425]: cannot find value `j` in this scope - --> $DIR/bad-if-let-suggestion.rs:13:13 + --> $DIR/bad-if-let-suggestion.rs:12:13 | LL | fn a() { | ------ similarly named function `a` defined here @@ -29,7 +29,7 @@ LL | if (i + j) = i {} | ^ help: a function with a similar name exists: `a` error[E0425]: cannot find value `i` in this scope - --> $DIR/bad-if-let-suggestion.rs:13:18 + --> $DIR/bad-if-let-suggestion.rs:12:18 | LL | fn a() { | ------ similarly named function `a` defined here @@ -38,7 +38,7 @@ LL | if (i + j) = i {} | ^ help: a function with a similar name exists: `a` error[E0425]: cannot find value `x` in this scope - --> $DIR/bad-if-let-suggestion.rs:20:8 + --> $DIR/bad-if-let-suggestion.rs:19:8 | LL | fn a() { | ------ similarly named function `a` defined here @@ -46,15 +46,6 @@ LL | fn a() { LL | if x[0] = 1 {} | ^ help: a function with a similar name exists: `a` -error[E0658]: `let` expressions in this position are unstable - --> $DIR/bad-if-let-suggestion.rs:5:8 - | -LL | if let x = 1 && i = 2 {} - | ^^^^^^^^^ - | - = note: see issue #53667 for more information - = help: add `#![feature(let_chains)]` to the crate attributes to enable - error[E0308]: mismatched types --> $DIR/bad-if-let-suggestion.rs:5:8 | @@ -66,7 +57,7 @@ help: you might have meant to compare for equality LL | if let x = 1 && i == 2 {} | + -error: aborting due to 8 previous errors +error: aborting due to 7 previous errors -Some errors have detailed explanations: E0308, E0425, E0658. +Some errors have detailed explanations: E0308, E0425. For more information about an error, try `rustc --explain E0308`. diff --git a/tests/ui/rfcs/rfc-2294-if-let-guard/feature-gate.rs b/tests/ui/rfcs/rfc-2294-if-let-guard/feature-gate.rs index 21f2a41cb1b..b8c0eb3e6d6 100644 --- a/tests/ui/rfcs/rfc-2294-if-let-guard/feature-gate.rs +++ b/tests/ui/rfcs/rfc-2294-if-let-guard/feature-gate.rs @@ -9,11 +9,9 @@ fn _if_let_guard() { () if (let 0 = 1) => {} //~^ ERROR expected expression, found `let` statement - //~| ERROR `let` expressions in this position are unstable () if (((let 0 = 1))) => {} //~^ ERROR expected expression, found `let` statement - //~| ERROR `let` expressions in this position are unstable () if true && let 0 = 1 => {} //~^ ERROR `if let` guards are experimental @@ -25,25 +23,18 @@ fn _if_let_guard() { () if (let 0 = 1) && true => {} //~^ ERROR expected expression, found `let` statement - //~| ERROR `let` expressions in this position are unstable () if true && (let 0 = 1) => {} //~^ ERROR expected expression, found `let` statement - //~| ERROR `let` expressions in this position are unstable () if (let 0 = 1) && (let 0 = 1) => {} //~^ ERROR expected expression, found `let` statement //~| ERROR expected expression, found `let` statement - //~| ERROR `let` expressions in this position are unstable - //~| ERROR `let` expressions in this position are unstable () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {} //~^ ERROR `if let` guards are experimental //~| ERROR `let` expressions in this position are unstable //~| ERROR `let` expressions in this position are unstable - //~| ERROR `let` expressions in this position are unstable - //~| ERROR `let` expressions in this position are unstable - //~| ERROR `let` expressions in this position are unstable //~| ERROR expected expression, found `let` statement //~| ERROR expected expression, found `let` statement //~| ERROR expected expression, found `let` statement 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 d5187ba1afc..a21ecae4eae 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 @@ -11,115 +11,115 @@ LL | () if (let 0 = 1) => {} | ^^^^^^^^^ error: expected expression, found `let` statement - --> $DIR/feature-gate.rs:14:18 + --> $DIR/feature-gate.rs:13:18 | LL | () if (((let 0 = 1))) => {} | ^^^^^^^^^ | note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/feature-gate.rs:14:18 + --> $DIR/feature-gate.rs:13:18 | LL | () if (((let 0 = 1))) => {} | ^^^^^^^^^ error: expected expression, found `let` statement - --> $DIR/feature-gate.rs:26:16 + --> $DIR/feature-gate.rs:24:16 | LL | () if (let 0 = 1) && true => {} | ^^^^^^^^^ | note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/feature-gate.rs:26:16 + --> $DIR/feature-gate.rs:24:16 | LL | () if (let 0 = 1) && true => {} | ^^^^^^^^^ error: expected expression, found `let` statement - --> $DIR/feature-gate.rs:30:24 + --> $DIR/feature-gate.rs:27:24 | LL | () if true && (let 0 = 1) => {} | ^^^^^^^^^ | note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/feature-gate.rs:30:24 + --> $DIR/feature-gate.rs:27:24 | LL | () if true && (let 0 = 1) => {} | ^^^^^^^^^ error: expected expression, found `let` statement - --> $DIR/feature-gate.rs:34:16 + --> $DIR/feature-gate.rs:30:16 | LL | () if (let 0 = 1) && (let 0 = 1) => {} | ^^^^^^^^^ | note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/feature-gate.rs:34:16 + --> $DIR/feature-gate.rs:30:16 | LL | () if (let 0 = 1) && (let 0 = 1) => {} | ^^^^^^^^^ error: expected expression, found `let` statement - --> $DIR/feature-gate.rs:34:31 + --> $DIR/feature-gate.rs:30:31 | LL | () if (let 0 = 1) && (let 0 = 1) => {} | ^^^^^^^^^ | note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/feature-gate.rs:34:31 + --> $DIR/feature-gate.rs:30:31 | LL | () if (let 0 = 1) && (let 0 = 1) => {} | ^^^^^^^^^ error: expected expression, found `let` statement - --> $DIR/feature-gate.rs:40:42 + --> $DIR/feature-gate.rs:34:42 | LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {} | ^^^^^^^^^ | note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/feature-gate.rs:40:42 + --> $DIR/feature-gate.rs:34:42 | LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: expected expression, found `let` statement - --> $DIR/feature-gate.rs:40:55 + --> $DIR/feature-gate.rs:34:55 | LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {} | ^^^^^^^^^ | note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/feature-gate.rs:40:42 + --> $DIR/feature-gate.rs:34:42 | LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: expected expression, found `let` statement - --> $DIR/feature-gate.rs:40:68 + --> $DIR/feature-gate.rs:34:68 | LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {} | ^^^^^^^^^ | note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/feature-gate.rs:40:42 + --> $DIR/feature-gate.rs:34:42 | LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: expected expression, found `let` statement - --> $DIR/feature-gate.rs:69:16 + --> $DIR/feature-gate.rs:60:16 | LL | use_expr!((let 0 = 1 && 0 == 0)); | ^^^ error: expected expression, found `let` statement - --> $DIR/feature-gate.rs:71:16 + --> $DIR/feature-gate.rs:62:16 | LL | use_expr!((let 0 = 1)); | ^^^ error: no rules expected the token `let` - --> $DIR/feature-gate.rs:79:15 + --> $DIR/feature-gate.rs:70:15 | LL | macro_rules! use_expr { | --------------------- when calling this macro @@ -128,7 +128,7 @@ LL | use_expr!(let 0 = 1); | ^^^ no rules expected this token in macro call | note: while trying to match meta-variable `$e:expr` - --> $DIR/feature-gate.rs:62:10 + --> $DIR/feature-gate.rs:53:10 | LL | ($e:expr) => { | ^^^^^^^ @@ -144,7 +144,7 @@ LL | () if let 0 = 1 => {} = help: you can write `if matches!(, )` instead of `if let = ` error[E0658]: `if let` guards are experimental - --> $DIR/feature-gate.rs:18:12 + --> $DIR/feature-gate.rs:16:12 | LL | () if true && let 0 = 1 => {} | ^^^^^^^^^^^^^^^^^^^^ @@ -154,7 +154,7 @@ LL | () if true && let 0 = 1 => {} = help: you can write `if matches!(, )` instead of `if let = ` error[E0658]: `if let` guards are experimental - --> $DIR/feature-gate.rs:22:12 + --> $DIR/feature-gate.rs:20:12 | LL | () if let 0 = 1 && true => {} | ^^^^^^^^^^^^^^^^^^^^ @@ -164,7 +164,7 @@ LL | () if let 0 = 1 && true => {} = help: you can write `if matches!(, )` instead of `if let = ` error[E0658]: `if let` guards are experimental - --> $DIR/feature-gate.rs:40:12 + --> $DIR/feature-gate.rs:34:12 | LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -174,7 +174,7 @@ LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = = help: you can write `if matches!(, )` instead of `if let = ` error[E0658]: `if let` guards are experimental - --> $DIR/feature-gate.rs:52:12 + --> $DIR/feature-gate.rs:43:12 | LL | () if let Range { start: _, end: _ } = (true..true) && false => {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -184,7 +184,7 @@ LL | () if let Range { start: _, end: _ } = (true..true) && false => {} = help: you can write `if matches!(, )` instead of `if let = ` error[E0658]: `if let` guards are experimental - --> $DIR/feature-gate.rs:75:12 + --> $DIR/feature-gate.rs:66:12 | LL | () if let 0 = 1 => {} | ^^^^^^^^^^^^ @@ -194,25 +194,7 @@ LL | () if let 0 = 1 => {} = help: you can write `if matches!(, )` instead of `if let = ` error[E0658]: `let` expressions in this position are unstable - --> $DIR/feature-gate.rs:10:16 - | -LL | () if (let 0 = 1) => {} - | ^^^^^^^^^ - | - = note: see issue #53667 for more information - = help: add `#![feature(let_chains)]` to the crate attributes to enable - -error[E0658]: `let` expressions in this position are unstable - --> $DIR/feature-gate.rs:14:18 - | -LL | () if (((let 0 = 1))) => {} - | ^^^^^^^^^ - | - = note: see issue #53667 for more information - = help: add `#![feature(let_chains)]` to the crate attributes to enable - -error[E0658]: `let` expressions in this position are unstable - --> $DIR/feature-gate.rs:18:23 + --> $DIR/feature-gate.rs:16:23 | LL | () if true && let 0 = 1 => {} | ^^^^^^^^^ @@ -221,7 +203,7 @@ LL | () if true && let 0 = 1 => {} = help: add `#![feature(let_chains)]` to the crate attributes to enable error[E0658]: `let` expressions in this position are unstable - --> $DIR/feature-gate.rs:22:15 + --> $DIR/feature-gate.rs:20:15 | LL | () if let 0 = 1 && true => {} | ^^^^^^^^^ @@ -230,43 +212,7 @@ LL | () if let 0 = 1 && true => {} = help: add `#![feature(let_chains)]` to the crate attributes to enable error[E0658]: `let` expressions in this position are unstable - --> $DIR/feature-gate.rs:26:16 - | -LL | () if (let 0 = 1) && true => {} - | ^^^^^^^^^ - | - = note: see issue #53667 for more information - = help: add `#![feature(let_chains)]` to the crate attributes to enable - -error[E0658]: `let` expressions in this position are unstable - --> $DIR/feature-gate.rs:30:24 - | -LL | () if true && (let 0 = 1) => {} - | ^^^^^^^^^ - | - = note: see issue #53667 for more information - = help: add `#![feature(let_chains)]` to the crate attributes to enable - -error[E0658]: `let` expressions in this position are unstable - --> $DIR/feature-gate.rs:34:16 - | -LL | () if (let 0 = 1) && (let 0 = 1) => {} - | ^^^^^^^^^ - | - = note: see issue #53667 for more information - = help: add `#![feature(let_chains)]` to the crate attributes to enable - -error[E0658]: `let` expressions in this position are unstable - --> $DIR/feature-gate.rs:34:31 - | -LL | () if (let 0 = 1) && (let 0 = 1) => {} - | ^^^^^^^^^ - | - = note: see issue #53667 for more information - = help: add `#![feature(let_chains)]` to the crate attributes to enable - -error[E0658]: `let` expressions in this position are unstable - --> $DIR/feature-gate.rs:40:15 + --> $DIR/feature-gate.rs:34:15 | LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {} | ^^^^^^^^^ @@ -275,7 +221,7 @@ LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = = help: add `#![feature(let_chains)]` to the crate attributes to enable error[E0658]: `let` expressions in this position are unstable - --> $DIR/feature-gate.rs:40:28 + --> $DIR/feature-gate.rs:34:28 | LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {} | ^^^^^^^^^ @@ -284,34 +230,7 @@ LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = = help: add `#![feature(let_chains)]` to the crate attributes to enable error[E0658]: `let` expressions in this position are unstable - --> $DIR/feature-gate.rs:40:42 - | -LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {} - | ^^^^^^^^^ - | - = note: see issue #53667 for more information - = help: add `#![feature(let_chains)]` to the crate attributes to enable - -error[E0658]: `let` expressions in this position are unstable - --> $DIR/feature-gate.rs:40:55 - | -LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {} - | ^^^^^^^^^ - | - = note: see issue #53667 for more information - = help: add `#![feature(let_chains)]` to the crate attributes to enable - -error[E0658]: `let` expressions in this position are unstable - --> $DIR/feature-gate.rs:40:68 - | -LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {} - | ^^^^^^^^^ - | - = note: see issue #53667 for more information - = help: add `#![feature(let_chains)]` to the crate attributes to enable - -error[E0658]: `let` expressions in this position are unstable - --> $DIR/feature-gate.rs:52:15 + --> $DIR/feature-gate.rs:43:15 | LL | () if let Range { start: _, end: _ } = (true..true) && false => {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -319,6 +238,6 @@ LL | () if let Range { start: _, end: _ } = (true..true) && false => {} = note: see issue #53667 for more information = help: add `#![feature(let_chains)]` to the crate attributes to enable -error: aborting due to 32 previous errors +error: aborting due to 23 previous errors For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/rfcs/rfc-2497-if-let-chains/disallowed-positions-without-feature-gate.rs b/tests/ui/rfcs/rfc-2497-if-let-chains/disallowed-positions-without-feature-gate.rs new file mode 100644 index 00000000000..096036bb133 --- /dev/null +++ b/tests/ui/rfcs/rfc-2497-if-let-chains/disallowed-positions-without-feature-gate.rs @@ -0,0 +1,340 @@ +// Check that we don't suggest enabling a feature for code that's +// not accepted even with that feature. + +#![allow(irrefutable_let_patterns)] + +use std::ops::Range; + +fn main() {} + +fn _if() { + if (let 0 = 1) {} + //~^ ERROR expected expression, found `let` statement + + if (((let 0 = 1))) {} + //~^ ERROR expected expression, found `let` statement + + if (let 0 = 1) && true {} + //~^ ERROR expected expression, found `let` statement + + if true && (let 0 = 1) {} + //~^ ERROR expected expression, found `let` statement + + if (let 0 = 1) && (let 0 = 1) {} + //~^ ERROR expected expression, found `let` statement + //~| ERROR expected expression, found `let` statement + + if (let 2 = 3 && let 3 = 4 && let 4 = 5) {} + //~^ ERROR expected expression, found `let` statement + //~| ERROR expected expression, found `let` statement + //~| ERROR expected expression, found `let` statement +} + +fn _while() { + while (let 0 = 1) {} + //~^ ERROR expected expression, found `let` statement + + while (((let 0 = 1))) {} + //~^ ERROR expected expression, found `let` statement + + while (let 0 = 1) && true {} + //~^ ERROR expected expression, found `let` statement + + while true && (let 0 = 1) {} + //~^ ERROR expected expression, found `let` statement + + while (let 0 = 1) && (let 0 = 1) {} + //~^ ERROR expected expression, found `let` statement + //~| ERROR expected expression, found `let` statement + + while (let 2 = 3 && let 3 = 4 && let 4 = 5) {} + //~^ ERROR expected expression, found `let` statement + //~| ERROR expected expression, found `let` statement + //~| ERROR expected expression, found `let` statement +} + +fn _macros() { + macro_rules! use_expr { + ($e:expr) => { + if $e {} + while $e {} + } + } + use_expr!((let 0 = 1 && 0 == 0)); + //~^ ERROR expected expression, found `let` statement + use_expr!((let 0 = 1)); + //~^ ERROR expected expression, found `let` statement +} + +fn nested_within_if_expr() { + if &let 0 = 0 {} + //~^ ERROR expected expression, found `let` statement + + if !let 0 = 0 {} + //~^ ERROR expected expression, found `let` statement + if *let 0 = 0 {} + //~^ ERROR expected expression, found `let` statement + if -let 0 = 0 {} + //~^ ERROR expected expression, found `let` statement + + fn _check_try_binds_tighter() -> Result<(), ()> { + if let 0 = 0? {} + //~^ ERROR the `?` operator can only be applied to values that implement `Try` + Ok(()) + } + if (let 0 = 0)? {} + //~^ ERROR expected expression, found `let` statement + + if true || let 0 = 0 {} + //~^ ERROR expected expression, found `let` statement + if (true || let 0 = 0) {} + //~^ ERROR expected expression, found `let` statement + if true && (true || let 0 = 0) {} + //~^ ERROR expected expression, found `let` statement + if true || (true && let 0 = 0) {} + //~^ ERROR expected expression, found `let` statement + + let mut x = true; + if x = let 0 = 0 {} + //~^ ERROR expected expression, found `let` statement + + if true..(let 0 = 0) {} + //~^ ERROR expected expression, found `let` statement + //~| ERROR mismatched types + if ..(let 0 = 0) {} + //~^ ERROR expected expression, found `let` statement + if (let 0 = 0).. {} + //~^ ERROR expected expression, found `let` statement + + // Binds as `(let ... = true)..true &&/|| false`. + if let Range { start: _, end: _ } = true..true && false {} + //~^ ERROR expected expression, found `let` statement + //~| ERROR mismatched types + if let Range { start: _, end: _ } = true..true || false {} + //~^ ERROR expected expression, found `let` statement + //~| ERROR mismatched types + + // Binds as `(let Range { start: F, end } = F)..(|| true)`. + const F: fn() -> bool = || true; + if let Range { start: F, end } = F..|| true {} + //~^ ERROR expected expression, found `let` statement + //~| ERROR mismatched types + + // Binds as `(let Range { start: true, end } = t)..(&&false)`. + let t = &&true; + if let Range { start: true, end } = t..&&false {} + //~^ ERROR expected expression, found `let` statement + //~| ERROR mismatched types + + if let true = let true = true {} + //~^ ERROR expected expression, found `let` statement +} + +fn nested_within_while_expr() { + while &let 0 = 0 {} + //~^ ERROR expected expression, found `let` statement + + while !let 0 = 0 {} + //~^ ERROR expected expression, found `let` statement + while *let 0 = 0 {} + //~^ ERROR expected expression, found `let` statement + while -let 0 = 0 {} + //~^ ERROR expected expression, found `let` statement + + fn _check_try_binds_tighter() -> Result<(), ()> { + while let 0 = 0? {} + //~^ ERROR the `?` operator can only be applied to values that implement `Try` + Ok(()) + } + while (let 0 = 0)? {} + //~^ ERROR expected expression, found `let` statement + + while true || let 0 = 0 {} + //~^ ERROR expected expression, found `let` statement + while (true || let 0 = 0) {} + //~^ ERROR expected expression, found `let` statement + while true && (true || let 0 = 0) {} + //~^ ERROR expected expression, found `let` statement + while true || (true && let 0 = 0) {} + //~^ ERROR expected expression, found `let` statement + + let mut x = true; + while x = let 0 = 0 {} + //~^ ERROR expected expression, found `let` statement + + while true..(let 0 = 0) {} + //~^ ERROR expected expression, found `let` statement + //~| ERROR mismatched types + while ..(let 0 = 0) {} + //~^ ERROR expected expression, found `let` statement + while (let 0 = 0).. {} + //~^ ERROR expected expression, found `let` statement + + // Binds as `(let ... = true)..true &&/|| false`. + while let Range { start: _, end: _ } = true..true && false {} + //~^ ERROR expected expression, found `let` statement + //~| ERROR mismatched types + while let Range { start: _, end: _ } = true..true || false {} + //~^ ERROR expected expression, found `let` statement + //~| ERROR mismatched types + + // Binds as `(let Range { start: F, end } = F)..(|| true)`. + const F: fn() -> bool = || true; + while let Range { start: F, end } = F..|| true {} + //~^ ERROR expected expression, found `let` statement + //~| ERROR mismatched types + + // Binds as `(let Range { start: true, end } = t)..(&&false)`. + let t = &&true; + while let Range { start: true, end } = t..&&false {} + //~^ ERROR expected expression, found `let` statement + //~| ERROR mismatched types + + while let true = let true = true {} + //~^ ERROR expected expression, found `let` statement +} + +fn not_error_because_clarified_intent() { + if let Range { start: _, end: _ } = (true..true || false) { } + + if let Range { start: _, end: _ } = (true..true && false) { } + + while let Range { start: _, end: _ } = (true..true || false) { } + + while let Range { start: _, end: _ } = (true..true && false) { } +} + +fn outside_if_and_while_expr() { + &let 0 = 0; + //~^ ERROR expected expression, found `let` statement + + !let 0 = 0; + //~^ ERROR expected expression, found `let` statement + *let 0 = 0; + //~^ ERROR expected expression, found `let` statement + -let 0 = 0; + //~^ ERROR expected expression, found `let` statement + let _ = let _ = 3; + //~^ ERROR expected expression, found `let` statement + + fn _check_try_binds_tighter() -> Result<(), ()> { + let 0 = 0?; + //~^ ERROR the `?` operator can only be applied to values that implement `Try` + Ok(()) + } + (let 0 = 0)?; + //~^ ERROR expected expression, found `let` statement + + true || let 0 = 0; + //~^ ERROR expected expression, found `let` statement + (true || let 0 = 0); + //~^ ERROR expected expression, found `let` statement + true && (true || let 0 = 0); + //~^ ERROR expected expression, found `let` statement + + let mut x = true; + x = let 0 = 0; + //~^ ERROR expected expression, found `let` statement + + true..(let 0 = 0); + //~^ ERROR expected expression, found `let` statement + ..(let 0 = 0); + //~^ ERROR expected expression, found `let` statement + (let 0 = 0)..; + //~^ ERROR expected expression, found `let` statement + + (let Range { start: _, end: _ } = true..true || false); + //~^ ERROR mismatched types + //~| ERROR expected expression, found `let` statement + + (let true = let true = true); + //~^ ERROR expected expression, found `let` statement + //~| ERROR expected expression, found `let` statement + + { + #[cfg(FALSE)] + let x = true && let y = 1; + //~^ ERROR expected expression, found `let` statement + } + + #[cfg(FALSE)] + { + [1, 2, 3][let _ = ()] + //~^ ERROR expected expression, found `let` statement + } + + // Check function tail position. + &let 0 = 0 + //~^ ERROR expected expression, found `let` statement +} + +// Let's make sure that `let` inside const generic arguments are considered. +fn inside_const_generic_arguments() { + struct A; + impl A<{B}> { const O: u32 = 5; } + + if let A::<{ + true && let 1 = 1 + //~^ ERROR expected expression, found `let` statement + }>::O = 5 {} + + while let A::<{ + true && let 1 = 1 + //~^ ERROR expected expression, found `let` statement + }>::O = 5 {} + + if A::<{ + true && let 1 = 1 + //~^ ERROR expected expression, found `let` statement + }>::O == 5 {} + + // In the cases above we have `ExprKind::Block` to help us out. + // Below however, we would not have a block and so an implementation might go + // from visiting expressions to types without banning `let` expressions down the tree. + // This tests ensures that we are not caught by surprise should the parser + // admit non-IDENT expressions in const generic arguments. + + if A::< + true && let 1 = 1 + //~^ ERROR expressions must be enclosed in braces + //~| ERROR expected expression, found `let` statement + >::O == 5 {} +} + +fn with_parenthesis() { + let opt = Some(Some(1i32)); + + if (let Some(a) = opt && true) { + //~^ ERROR expected expression, found `let` statement + } + + if (let Some(a) = opt) && true { + //~^ ERROR expected expression, found `let` statement + } + if (let Some(a) = opt) && (let Some(b) = a) { + //~^ ERROR expected expression, found `let` statement + //~| ERROR expected expression, found `let` statement + } + + if (let Some(a) = opt && (let Some(b) = a)) && b == 1 { + //~^ ERROR expected expression, found `let` statement + //~| ERROR expected expression, found `let` statement + } + if (let Some(a) = opt && (let Some(b) = a)) && true { + //~^ ERROR expected expression, found `let` statement + //~| ERROR expected expression, found `let` statement + } + if (let Some(a) = opt && (true)) && true { + //~^ ERROR expected expression, found `let` statement + } + + #[cfg(FALSE)] + let x = (true && let y = 1); + //~^ ERROR expected expression, found `let` statement + + #[cfg(FALSE)] + { + ([1, 2, 3][let _ = ()]) + //~^ ERROR expected expression, found `let` statement + } +} 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 new file mode 100644 index 00000000000..218ca254d0f --- /dev/null +++ b/tests/ui/rfcs/rfc-2497-if-let-chains/disallowed-positions-without-feature-gate.stderr @@ -0,0 +1,870 @@ +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:11:9 + | +LL | if (let 0 = 1) {} + | ^^^^^^^^^ + | +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:11:9 + | +LL | if (let 0 = 1) {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:14:11 + | +LL | if (((let 0 = 1))) {} + | ^^^^^^^^^ + | +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:14:11 + | +LL | if (((let 0 = 1))) {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:17:9 + | +LL | if (let 0 = 1) && true {} + | ^^^^^^^^^ + | +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:17:9 + | +LL | if (let 0 = 1) && true {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:20:17 + | +LL | if true && (let 0 = 1) {} + | ^^^^^^^^^ + | +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:20:17 + | +LL | if true && (let 0 = 1) {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:23:9 + | +LL | if (let 0 = 1) && (let 0 = 1) {} + | ^^^^^^^^^ + | +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:23:9 + | +LL | if (let 0 = 1) && (let 0 = 1) {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:23:24 + | +LL | if (let 0 = 1) && (let 0 = 1) {} + | ^^^^^^^^^ + | +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:23:24 + | +LL | if (let 0 = 1) && (let 0 = 1) {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:27:9 + | +LL | if (let 2 = 3 && let 3 = 4 && let 4 = 5) {} + | ^^^^^^^^^ + | +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:27:9 + | +LL | if (let 2 = 3 && let 3 = 4 && let 4 = 5) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:27:22 + | +LL | if (let 2 = 3 && let 3 = 4 && let 4 = 5) {} + | ^^^^^^^^^ + | +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:27:9 + | +LL | if (let 2 = 3 && let 3 = 4 && let 4 = 5) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:27:35 + | +LL | if (let 2 = 3 && let 3 = 4 && let 4 = 5) {} + | ^^^^^^^^^ + | +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:27:9 + | +LL | if (let 2 = 3 && let 3 = 4 && let 4 = 5) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:34:12 + | +LL | while (let 0 = 1) {} + | ^^^^^^^^^ + | +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:34:12 + | +LL | while (let 0 = 1) {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:37:14 + | +LL | while (((let 0 = 1))) {} + | ^^^^^^^^^ + | +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:37:14 + | +LL | while (((let 0 = 1))) {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:40:12 + | +LL | while (let 0 = 1) && true {} + | ^^^^^^^^^ + | +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:40:12 + | +LL | while (let 0 = 1) && true {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:43:20 + | +LL | while true && (let 0 = 1) {} + | ^^^^^^^^^ + | +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:43:20 + | +LL | while true && (let 0 = 1) {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:46:12 + | +LL | while (let 0 = 1) && (let 0 = 1) {} + | ^^^^^^^^^ + | +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:46:12 + | +LL | while (let 0 = 1) && (let 0 = 1) {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:46:27 + | +LL | while (let 0 = 1) && (let 0 = 1) {} + | ^^^^^^^^^ + | +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:46:27 + | +LL | while (let 0 = 1) && (let 0 = 1) {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:50:12 + | +LL | while (let 2 = 3 && let 3 = 4 && let 4 = 5) {} + | ^^^^^^^^^ + | +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:50:12 + | +LL | while (let 2 = 3 && let 3 = 4 && let 4 = 5) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:50:25 + | +LL | while (let 2 = 3 && let 3 = 4 && let 4 = 5) {} + | ^^^^^^^^^ + | +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:50:12 + | +LL | while (let 2 = 3 && let 3 = 4 && let 4 = 5) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:50:38 + | +LL | while (let 2 = 3 && let 3 = 4 && let 4 = 5) {} + | ^^^^^^^^^ + | +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:50:12 + | +LL | while (let 2 = 3 && let 3 = 4 && let 4 = 5) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:70:9 + | +LL | if &let 0 = 0 {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:73:9 + | +LL | if !let 0 = 0 {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:75:9 + | +LL | if *let 0 = 0 {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:77:9 + | +LL | if -let 0 = 0 {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:85:9 + | +LL | if (let 0 = 0)? {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:88:16 + | +LL | if true || let 0 = 0 {} + | ^^^^^^^^^ + | +note: `||` operators are not supported in let chain expressions + --> $DIR/disallowed-positions-without-feature-gate.rs:88:13 + | +LL | if true || let 0 = 0 {} + | ^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:90:17 + | +LL | if (true || let 0 = 0) {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:92:25 + | +LL | if true && (true || let 0 = 0) {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:94:25 + | +LL | if true || (true && let 0 = 0) {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:98:12 + | +LL | if x = let 0 = 0 {} + | ^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:101:15 + | +LL | if true..(let 0 = 0) {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:104:11 + | +LL | if ..(let 0 = 0) {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:106:9 + | +LL | if (let 0 = 0).. {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:110:8 + | +LL | if let Range { start: _, end: _ } = true..true && false {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:113:8 + | +LL | if let Range { start: _, end: _ } = true..true || false {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:119:8 + | +LL | if let Range { start: F, end } = F..|| true {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:125:8 + | +LL | if let Range { start: true, end } = t..&&false {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:129:19 + | +LL | if let true = let true = true {} + | ^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:134:12 + | +LL | while &let 0 = 0 {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:137:12 + | +LL | while !let 0 = 0 {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:139:12 + | +LL | while *let 0 = 0 {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:141:12 + | +LL | while -let 0 = 0 {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:149:12 + | +LL | while (let 0 = 0)? {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:152:19 + | +LL | while true || let 0 = 0 {} + | ^^^^^^^^^ + | +note: `||` operators are not supported in let chain expressions + --> $DIR/disallowed-positions-without-feature-gate.rs:152:16 + | +LL | while true || let 0 = 0 {} + | ^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:154:20 + | +LL | while (true || let 0 = 0) {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:156:28 + | +LL | while true && (true || let 0 = 0) {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:158:28 + | +LL | while true || (true && let 0 = 0) {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:162:15 + | +LL | while x = let 0 = 0 {} + | ^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:165:18 + | +LL | while true..(let 0 = 0) {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:168:14 + | +LL | while ..(let 0 = 0) {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:170:12 + | +LL | while (let 0 = 0).. {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:174:11 + | +LL | while let Range { start: _, end: _ } = true..true && false {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:177:11 + | +LL | while let Range { start: _, end: _ } = true..true || false {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:183:11 + | +LL | while let Range { start: F, end } = F..|| true {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:189:11 + | +LL | while let Range { start: true, end } = t..&&false {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:193:22 + | +LL | while let true = let true = true {} + | ^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:208:6 + | +LL | &let 0 = 0; + | ^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:211:6 + | +LL | !let 0 = 0; + | ^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:213:6 + | +LL | *let 0 = 0; + | ^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:215:6 + | +LL | -let 0 = 0; + | ^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:217:13 + | +LL | let _ = let _ = 3; + | ^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:225:6 + | +LL | (let 0 = 0)?; + | ^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:228:13 + | +LL | true || let 0 = 0; + | ^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:230:14 + | +LL | (true || let 0 = 0); + | ^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:232:22 + | +LL | true && (true || let 0 = 0); + | ^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:236:9 + | +LL | x = let 0 = 0; + | ^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:239:12 + | +LL | true..(let 0 = 0); + | ^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:241:8 + | +LL | ..(let 0 = 0); + | ^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:243:6 + | +LL | (let 0 = 0)..; + | ^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:246:6 + | +LL | (let Range { start: _, end: _ } = true..true || false); + | ^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:250:6 + | +LL | (let true = let true = true); + | ^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:250:17 + | +LL | (let true = let true = true); + | ^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:256:25 + | +LL | let x = true && let y = 1; + | ^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:262:19 + | +LL | [1, 2, 3][let _ = ()] + | ^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:267:6 + | +LL | &let 0 = 0 + | ^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:277:17 + | +LL | true && let 1 = 1 + | ^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:282:17 + | +LL | true && let 1 = 1 + | ^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:287:17 + | +LL | true && let 1 = 1 + | ^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:298:17 + | +LL | true && let 1 = 1 + | ^^^ + +error: expressions must be enclosed in braces to be used as const generic arguments + --> $DIR/disallowed-positions-without-feature-gate.rs:298:9 + | +LL | true && let 1 = 1 + | ^^^^^^^^^^^^^^^^^ + | +help: enclose the `const` expression in braces + | +LL | { true && let 1 = 1 } + | + + + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:307:9 + | +LL | if (let Some(a) = opt && true) { + | ^^^^^^^^^^^^^^^^^ + | +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:307:9 + | +LL | if (let Some(a) = opt && true) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:311:9 + | +LL | if (let Some(a) = opt) && true { + | ^^^^^^^^^^^^^^^^^ + | +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:311:9 + | +LL | if (let Some(a) = opt) && true { + | ^^^^^^^^^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:314:9 + | +LL | if (let Some(a) = opt) && (let Some(b) = a) { + | ^^^^^^^^^^^^^^^^^ + | +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:314:9 + | +LL | if (let Some(a) = opt) && (let Some(b) = a) { + | ^^^^^^^^^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:314:32 + | +LL | if (let Some(a) = opt) && (let Some(b) = a) { + | ^^^^^^^^^^^^^^^ + | +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:314:32 + | +LL | if (let Some(a) = opt) && (let Some(b) = a) { + | ^^^^^^^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:319:9 + | +LL | if (let Some(a) = opt && (let Some(b) = a)) && b == 1 { + | ^^^^^^^^^^^^^^^^^ + | +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:319:9 + | +LL | if (let Some(a) = opt && (let Some(b) = a)) && b == 1 { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:319:31 + | +LL | if (let Some(a) = opt && (let Some(b) = a)) && b == 1 { + | ^^^^^^^^^^^^^^^ + | +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:319:31 + | +LL | if (let Some(a) = opt && (let Some(b) = a)) && b == 1 { + | ^^^^^^^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:323:9 + | +LL | if (let Some(a) = opt && (let Some(b) = a)) && true { + | ^^^^^^^^^^^^^^^^^ + | +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:323:9 + | +LL | if (let Some(a) = opt && (let Some(b) = a)) && true { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:323:31 + | +LL | if (let Some(a) = opt && (let Some(b) = a)) && true { + | ^^^^^^^^^^^^^^^ + | +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:323:31 + | +LL | if (let Some(a) = opt && (let Some(b) = a)) && true { + | ^^^^^^^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:327:9 + | +LL | if (let Some(a) = opt && (true)) && true { + | ^^^^^^^^^^^^^^^^^ + | +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:327:9 + | +LL | if (let Some(a) = opt && (true)) && true { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:332:22 + | +LL | let x = (true && let y = 1); + | ^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:337:20 + | +LL | ([1, 2, 3][let _ = ()]) + | ^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:63:16 + | +LL | use_expr!((let 0 = 1 && 0 == 0)); + | ^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:65:16 + | +LL | use_expr!((let 0 = 1)); + | ^^^ + +error[E0308]: mismatched types + --> $DIR/disallowed-positions-without-feature-gate.rs:101:8 + | +LL | if true..(let 0 = 0) {} + | ^^^^^^^^^^^^^^^^^ expected `bool`, found `Range` + | + = note: expected type `bool` + found struct `std::ops::Range` + +error[E0308]: mismatched types + --> $DIR/disallowed-positions-without-feature-gate.rs:110:12 + | +LL | if let Range { start: _, end: _ } = true..true && false {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ---- this expression has type `bool` + | | + | expected `bool`, found `Range<_>` + | + = note: expected type `bool` + found struct `std::ops::Range<_>` + +error[E0308]: mismatched types + --> $DIR/disallowed-positions-without-feature-gate.rs:113:12 + | +LL | if let Range { start: _, end: _ } = true..true || false {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ---- this expression has type `bool` + | | + | expected `bool`, found `Range<_>` + | + = note: expected type `bool` + found struct `std::ops::Range<_>` + +error[E0308]: mismatched types + --> $DIR/disallowed-positions-without-feature-gate.rs:119:12 + | +LL | if let Range { start: F, end } = F..|| true {} + | ^^^^^^^^^^^^^^^^^^^^^^^ - this expression has type `fn() -> bool` + | | + | expected fn pointer, found `Range<_>` + | + = note: expected fn pointer `fn() -> bool` + found struct `std::ops::Range<_>` + +error[E0308]: mismatched types + --> $DIR/disallowed-positions-without-feature-gate.rs:125:12 + | +LL | if let Range { start: true, end } = t..&&false {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - this expression has type `&&bool` + | | + | expected `bool`, found `Range<_>` + | + = note: expected type `bool` + found struct `std::ops::Range<_>` + +error[E0277]: the `?` operator can only be applied to values that implement `Try` + --> $DIR/disallowed-positions-without-feature-gate.rs:81:20 + | +LL | if let 0 = 0? {} + | ^^ the `?` operator cannot be applied to type `{integer}` + | + = help: the trait `Try` is not implemented for `{integer}` + +error[E0308]: mismatched types + --> $DIR/disallowed-positions-without-feature-gate.rs:165:11 + | +LL | while true..(let 0 = 0) {} + | ^^^^^^^^^^^^^^^^^ expected `bool`, found `Range` + | + = note: expected type `bool` + found struct `std::ops::Range` + +error[E0308]: mismatched types + --> $DIR/disallowed-positions-without-feature-gate.rs:174:15 + | +LL | while let Range { start: _, end: _ } = true..true && false {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ---- this expression has type `bool` + | | + | expected `bool`, found `Range<_>` + | + = note: expected type `bool` + found struct `std::ops::Range<_>` + +error[E0308]: mismatched types + --> $DIR/disallowed-positions-without-feature-gate.rs:177:15 + | +LL | while let Range { start: _, end: _ } = true..true || false {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ---- this expression has type `bool` + | | + | expected `bool`, found `Range<_>` + | + = note: expected type `bool` + found struct `std::ops::Range<_>` + +error[E0308]: mismatched types + --> $DIR/disallowed-positions-without-feature-gate.rs:183:15 + | +LL | while let Range { start: F, end } = F..|| true {} + | ^^^^^^^^^^^^^^^^^^^^^^^ - this expression has type `fn() -> bool` + | | + | expected fn pointer, found `Range<_>` + | + = note: expected fn pointer `fn() -> bool` + found struct `std::ops::Range<_>` + +error[E0308]: mismatched types + --> $DIR/disallowed-positions-without-feature-gate.rs:189:15 + | +LL | while let Range { start: true, end } = t..&&false {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - this expression has type `&&bool` + | | + | expected `bool`, found `Range<_>` + | + = note: expected type `bool` + found struct `std::ops::Range<_>` + +error[E0277]: the `?` operator can only be applied to values that implement `Try` + --> $DIR/disallowed-positions-without-feature-gate.rs:145:23 + | +LL | while let 0 = 0? {} + | ^^ the `?` operator cannot be applied to type `{integer}` + | + = help: the trait `Try` is not implemented for `{integer}` + +error[E0308]: mismatched types + --> $DIR/disallowed-positions-without-feature-gate.rs:246:10 + | +LL | (let Range { start: _, end: _ } = true..true || false); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ---- this expression has type `bool` + | | + | expected `bool`, found `Range<_>` + | + = note: expected type `bool` + found struct `std::ops::Range<_>` + +error[E0277]: the `?` operator can only be applied to values that implement `Try` + --> $DIR/disallowed-positions-without-feature-gate.rs:221:17 + | +LL | let 0 = 0?; + | ^^ the `?` operator cannot be applied to type `{integer}` + | + = help: the trait `Try` is not implemented for `{integer}` + +error: aborting due to 105 previous errors + +Some errors have detailed explanations: E0277, E0308. +For more information about an error, try `rustc --explain E0277`. -- cgit 1.4.1-3-g733a5 From e324a59eb6ba1a7883bf23ff42d425ca96960f2a Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Wed, 13 Sep 2023 15:00:31 +0000 Subject: Address review comments - Add doc comment to new type - Restore "only supported directly in conditions of `if` and `while` expressions" note - Rename variant with clearer name --- compiler/rustc_parse/messages.ftl | 1 + compiler/rustc_parse/src/errors.rs | 1 + compiler/rustc_parse/src/parser/expr.rs | 17 ++- tests/ui/expr/if/bad-if-let-suggestion.stderr | 2 + tests/ui/mir/issue-92893.stderr | 2 + .../rfcs/rfc-2294-if-let-guard/feature-gate.stderr | 13 ++ .../rfc-2294-if-let-guard/macro-expanded.stderr | 1 + tests/ui/rfcs/rfc-2294-if-let-guard/parens.stderr | 4 + .../ast-validate-guards.stderr | 1 + .../avoid-invalid-mir.stderr | 2 + ...isallowed-positions-without-feature-gate.stderr | 151 +++++++++++++++++++++ .../disallowed-positions.stderr | 149 ++++++++++++++++++++ ...t-else-does-not-interact-with-let-chains.stderr | 2 + .../rfc-2497-if-let-chains/feature-gate.stderr | 4 + .../invalid-let-in-a-valid-let-context.stderr | 16 +++ 15 files changed, 362 insertions(+), 4 deletions(-) (limited to 'compiler/rustc_parse/src/parser') 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 -- cgit 1.4.1-3-g733a5