about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser/expr.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-11-18 20:26:58 +0000
committerbors <bors@rust-lang.org>2022-11-18 20:26:58 +0000
commitb833ad56f46a0bbe0e8729512812a161e7dae28a (patch)
tree06ff2cca21b9852960818c4d0f79b3cac302a54c /compiler/rustc_parse/src/parser/expr.rs
parent70fe5f08fffd16dc20506f7d140e47b074f77964 (diff)
parent7e5e520c7daf193bc33f8dd12dfd9ec4ed1f261a (diff)
downloadrust-b833ad56f46a0bbe0e8729512812a161e7dae28a.tar.gz
rust-b833ad56f46a0bbe0e8729512812a161e7dae28a.zip
Auto merge of #104573 - matthiaskrgr:rollup-k36ybtp, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #101162 (Migrate rustc_resolve to use SessionDiagnostic, part # 1)
 - #103386 (Don't allow `CoerceUnsized` into `dyn*` (except for trait upcasting))
 - #103405 (Detect incorrect chaining of if and if let conditions and recover)
 - #103594 (Fix non-associativity of `Instant` math on `aarch64-apple-darwin` targets)
 - #104006 (Add variant_name function to `LangItem`)
 - #104494 (Migrate GUI test to use functions)
 - #104516 (rustdoc: clean up sidebar width CSS)
 - #104550 (fix a typo)

Failed merges:

 - #104554 (Use `ErrorGuaranteed::unchecked_claim_error_was_emitted` less)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_parse/src/parser/expr.rs')
-rw-r--r--compiler/rustc_parse/src/parser/expr.rs15
1 files changed, 13 insertions, 2 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs
index 413c58f1bff..9f680a60613 100644
--- a/compiler/rustc_parse/src/parser/expr.rs
+++ b/compiler/rustc_parse/src/parser/expr.rs
@@ -21,8 +21,8 @@ use crate::errors::{
     NoFieldsForFnCall, NotAsNegationOperator, NotAsNegationOperatorSub,
     OuterAttributeNotAllowedOnIfElse, ParenthesesWithStructFields,
     RequireColonAfterLabeledExpression, ShiftInterpretedAsGeneric, StructLiteralNotAllowedHere,
-    StructLiteralNotAllowedHereSugg, TildeAsUnaryOperator, UnexpectedTokenAfterLabel,
-    UnexpectedTokenAfterLabelSugg, WrapExpressionInParentheses,
+    StructLiteralNotAllowedHereSugg, TildeAsUnaryOperator, UnexpectedIfWithIf,
+    UnexpectedTokenAfterLabel, UnexpectedTokenAfterLabelSugg, WrapExpressionInParentheses,
 };
 use crate::maybe_recover_from_interpolated_ty_qpath;
 use core::mem;
@@ -2239,6 +2239,7 @@ impl<'a> Parser<'a> {
                 if let Some(block) = recover_block_from_condition(self) {
                     block
                 } else {
+                    self.error_on_extra_if(&cond)?;
                     // Parse block, which will always fail, but we can add a nice note to the error
                     self.parse_block().map_err(|mut err| {
                         err.span_note(
@@ -2375,6 +2376,16 @@ impl<'a> Parser<'a> {
         });
     }
 
+    fn error_on_extra_if(&mut self, cond: &P<Expr>) -> PResult<'a, ()> {
+        if let ExprKind::Binary(Spanned { span: binop_span, node: binop}, _, right) = &cond.kind &&
+            let BinOpKind::And = binop &&
+            let ExprKind::If(cond, ..) = &right.kind {
+                    Err(self.sess.create_err(UnexpectedIfWithIf(binop_span.shrink_to_hi().to(cond.span.shrink_to_lo()))))
+            } else {
+                Ok(())
+            }
+    }
+
     /// Parses `for <src_pat> in <src_expr> <src_loop_block>` (`for` token already eaten).
     fn parse_for_expr(&mut self, opt_label: Option<Label>, lo: Span) -> PResult<'a, P<Expr>> {
         // Record whether we are about to parse `for (`.