@@ -24,8 +24,8 @@ use crate::errors::{
24
24
NoFieldsForFnCall , NotAsNegationOperator , NotAsNegationOperatorSub ,
25
25
OctalFloatLiteralNotSupported , OuterAttributeNotAllowedOnIfElse , ParenthesesWithStructFields ,
26
26
RequireColonAfterLabeledExpression , ShiftInterpretedAsGeneric , StructLiteralNotAllowedHere ,
27
- StructLiteralNotAllowedHereSugg , TildeAsUnaryOperator , UnexpectedTokenAfterLabel ,
28
- UnexpectedTokenAfterLabelSugg , WrapExpressionInParentheses ,
27
+ StructLiteralNotAllowedHereSugg , TildeAsUnaryOperator , UnexpectedIfWithIf ,
28
+ UnexpectedTokenAfterLabel , UnexpectedTokenAfterLabelSugg , WrapExpressionInParentheses ,
29
29
} ;
30
30
use crate :: maybe_recover_from_interpolated_ty_qpath;
31
31
@@ -2279,6 +2279,7 @@ impl<'a> Parser<'a> {
2279
2279
if let Some ( block) = recover_block_from_condition ( self ) {
2280
2280
block
2281
2281
} else {
2282
+ self . error_on_extra_if ( & cond) ?;
2282
2283
// Parse block, which will always fail, but we can add a nice note to the error
2283
2284
self . parse_block ( ) . map_err ( |mut err| {
2284
2285
err. span_note (
@@ -2415,6 +2416,16 @@ impl<'a> Parser<'a> {
2415
2416
} ) ;
2416
2417
}
2417
2418
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
+
2418
2429
/// Parses `for <src_pat> in <src_expr> <src_loop_block>` (`for` token already eaten).
2419
2430
fn parse_for_expr ( & mut self , opt_label : Option < Label > , lo : Span ) -> PResult < ' a , P < Expr > > {
2420
2431
// Record whether we are about to parse `for (`.
0 commit comments