@@ -21,8 +21,8 @@ use crate::errors::{
2121 NoFieldsForFnCall , NotAsNegationOperator , NotAsNegationOperatorSub ,
2222 OuterAttributeNotAllowedOnIfElse , ParenthesesWithStructFields ,
2323 RequireColonAfterLabeledExpression , ShiftInterpretedAsGeneric , StructLiteralNotAllowedHere ,
24- StructLiteralNotAllowedHereSugg , TildeAsUnaryOperator , UnexpectedTokenAfterLabel ,
25- UnexpectedTokenAfterLabelSugg , WrapExpressionInParentheses ,
24+ StructLiteralNotAllowedHereSugg , TildeAsUnaryOperator , UnexpectedIfWithIf ,
25+ UnexpectedTokenAfterLabel , UnexpectedTokenAfterLabelSugg , WrapExpressionInParentheses ,
2626} ;
2727use crate :: maybe_recover_from_interpolated_ty_qpath;
2828use core:: mem;
@@ -2231,6 +2231,7 @@ impl<'a> Parser<'a> {
22312231 if let Some ( block) = recover_block_from_condition ( self ) {
22322232 block
22332233 } else {
2234+ self . error_on_extra_if ( & cond) ?;
22342235 // Parse block, which will always fail, but we can add a nice note to the error
22352236 self . parse_block ( ) . map_err ( |mut err| {
22362237 err. span_note (
@@ -2367,6 +2368,16 @@ impl<'a> Parser<'a> {
23672368 } ) ;
23682369 }
23692370
2371+ fn error_on_extra_if ( & mut self , cond : & P < Expr > ) -> PResult < ' a , ( ) > {
2372+ if let ExprKind :: Binary ( Spanned { span : binop_span, node : binop} , _, right) = & cond. kind &&
2373+ let BinOpKind :: And = binop &&
2374+ let ExprKind :: If ( cond, ..) = & right. kind {
2375+ Err ( self . sess . create_err ( UnexpectedIfWithIf ( binop_span. shrink_to_hi ( ) . to ( cond. span . shrink_to_lo ( ) ) ) ) )
2376+ } else {
2377+ Ok ( ( ) )
2378+ }
2379+ }
2380+
23702381 /// Parses `for <src_pat> in <src_expr> <src_loop_block>` (`for` token already eaten).
23712382 fn parse_for_expr ( & mut self , opt_label : Option < Label > , lo : Span ) -> PResult < ' a , P < Expr > > {
23722383 // Record whether we are about to parse `for (`.
0 commit comments