@@ -24,8 +24,8 @@ use crate::errors::{
2424 NoFieldsForFnCall , NotAsNegationOperator , NotAsNegationOperatorSub ,
2525 OctalFloatLiteralNotSupported , OuterAttributeNotAllowedOnIfElse , ParenthesesWithStructFields ,
2626 RequireColonAfterLabeledExpression , ShiftInterpretedAsGeneric , StructLiteralNotAllowedHere ,
27- StructLiteralNotAllowedHereSugg , TildeAsUnaryOperator , UnexpectedTokenAfterLabel ,
28- UnexpectedTokenAfterLabelSugg , WrapExpressionInParentheses ,
27+ StructLiteralNotAllowedHereSugg , TildeAsUnaryOperator , UnexpectedIfWithIf ,
28+ UnexpectedTokenAfterLabel , UnexpectedTokenAfterLabelSugg , WrapExpressionInParentheses ,
2929} ;
3030use crate :: maybe_recover_from_interpolated_ty_qpath;
3131
@@ -2279,6 +2279,7 @@ impl<'a> Parser<'a> {
22792279 if let Some ( block) = recover_block_from_condition ( self ) {
22802280 block
22812281 } else {
2282+ self . error_on_extra_if ( & cond) ?;
22822283 // Parse block, which will always fail, but we can add a nice note to the error
22832284 self . parse_block ( ) . map_err ( |mut err| {
22842285 err. span_note (
@@ -2415,6 +2416,16 @@ impl<'a> Parser<'a> {
24152416 } ) ;
24162417 }
24172418
2419+ fn error_on_extra_if ( & mut self , cond : & P < Expr > ) -> PResult < ' a , ( ) > {
2420+ if let ExprKind :: Binary ( Spanned { span : binop_span, node : binop} , _, right) = & cond. kind &&
2421+ let BinOpKind :: And = binop &&
2422+ let ExprKind :: If ( cond, ..) = & right. kind {
2423+ Err ( self . sess . create_err ( UnexpectedIfWithIf ( binop_span. shrink_to_hi ( ) . to ( cond. span . shrink_to_lo ( ) ) ) ) )
2424+ } else {
2425+ Ok ( ( ) )
2426+ }
2427+ }
2428+
24182429 /// Parses `for <src_pat> in <src_expr> <src_loop_block>` (`for` token already eaten).
24192430 fn parse_for_expr ( & mut self , opt_label : Option < Label > , lo : Span ) -> PResult < ' a , P < Expr > > {
24202431 // Record whether we are about to parse `for (`.
0 commit comments