@@ -21,8 +21,8 @@ use crate::errors::{
21
21
NoFieldsForFnCall , NotAsNegationOperator , NotAsNegationOperatorSub ,
22
22
OuterAttributeNotAllowedOnIfElse , ParenthesesWithStructFields ,
23
23
RequireColonAfterLabeledExpression , ShiftInterpretedAsGeneric , StructLiteralNotAllowedHere ,
24
- StructLiteralNotAllowedHereSugg , TildeAsUnaryOperator , UnexpectedTokenAfterLabel ,
25
- UnexpectedTokenAfterLabelSugg , WrapExpressionInParentheses ,
24
+ StructLiteralNotAllowedHereSugg , TildeAsUnaryOperator , UnexpectedIfWithIf ,
25
+ UnexpectedTokenAfterLabel , UnexpectedTokenAfterLabelSugg , WrapExpressionInParentheses ,
26
26
} ;
27
27
use crate :: maybe_recover_from_interpolated_ty_qpath;
28
28
use core:: mem;
@@ -2231,6 +2231,7 @@ impl<'a> Parser<'a> {
2231
2231
if let Some ( block) = recover_block_from_condition ( self ) {
2232
2232
block
2233
2233
} else {
2234
+ self . error_on_extra_if ( & cond) ?;
2234
2235
// Parse block, which will always fail, but we can add a nice note to the error
2235
2236
self . parse_block ( ) . map_err ( |mut err| {
2236
2237
err. span_note (
@@ -2367,6 +2368,16 @@ impl<'a> Parser<'a> {
2367
2368
} ) ;
2368
2369
}
2369
2370
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
+
2370
2381
/// Parses `for <src_pat> in <src_expr> <src_loop_block>` (`for` token already eaten).
2371
2382
fn parse_for_expr ( & mut self , opt_label : Option < Label > , lo : Span ) -> PResult < ' a , P < Expr > > {
2372
2383
// Record whether we are about to parse `for (`.
0 commit comments