@@ -570,6 +570,11 @@ impl<'a> Parser<'a> {
570
570
"check_no_chained_comparison: {:?} is not comparison" ,
571
571
outer_op,
572
572
) ;
573
+
574
+ let mk_err_expr = |this : & Self , span| {
575
+ Ok ( Some ( this. mk_expr ( span, ExprKind :: Err , ThinVec :: new ( ) ) ) )
576
+ } ;
577
+
573
578
match lhs. kind {
574
579
ExprKind :: Binary ( op, _, _) if op. node . is_comparison ( ) => {
575
580
// Respan to include both operators.
@@ -601,7 +606,7 @@ impl<'a> Parser<'a> {
601
606
( token:: Gt , -1 ) ,
602
607
( token:: BinOp ( token:: Shr ) , -2 ) ,
603
608
] ;
604
- self . consume_tts ( 1 , & modifiers[ ..] , & [ ] ) ;
609
+ self . consume_tts ( 1 , & modifiers[ ..] ) ;
605
610
606
611
if !& [
607
612
token:: OpenDelim ( token:: Paren ) ,
@@ -612,7 +617,7 @@ impl<'a> Parser<'a> {
612
617
mem:: replace ( self , snapshot. clone ( ) ) ;
613
618
}
614
619
}
615
- if token:: ModSep == self . token . kind {
620
+ return if token:: ModSep == self . token . kind {
616
621
// We have some certainty that this was a bad turbofish at this point.
617
622
// `foo< bar >::`
618
623
suggest ( & mut err) ;
@@ -628,18 +633,14 @@ impl<'a> Parser<'a> {
628
633
// FIXME: actually check that the two expressions in the binop are
629
634
// paths and resynthesize new fn call expression instead of using
630
635
// `ExprKind::Err` placeholder.
631
- return Ok ( Some ( self . mk_expr (
632
- lhs. span . to ( self . prev_span ) ,
633
- ExprKind :: Err ,
634
- ThinVec :: new ( ) ,
635
- ) ) ) ;
636
+ mk_err_expr ( self , lhs. span . to ( self . prev_span ) )
636
637
}
637
638
Err ( mut expr_err) => {
638
639
expr_err. cancel ( ) ;
639
640
// Not entirely sure now, but we bubble the error up with the
640
641
// suggestion.
641
642
mem:: replace ( self , snapshot) ;
642
- return Err ( err) ;
643
+ Err ( err)
643
644
}
644
645
}
645
646
} else if token:: OpenDelim ( token:: Paren ) == self . token . kind {
@@ -655,9 +656,9 @@ impl<'a> Parser<'a> {
655
656
( token:: OpenDelim ( token:: Paren ) , 1 ) ,
656
657
( token:: CloseDelim ( token:: Paren ) , -1 ) ,
657
658
] ;
658
- self . consume_tts ( 1 , & modifiers[ ..] , & [ ] ) ;
659
+ self . consume_tts ( 1 , & modifiers[ ..] ) ;
659
660
660
- return if self . token . kind == token:: Eof {
661
+ if self . token . kind == token:: Eof {
661
662
// Not entirely sure now, but we bubble the error up with the
662
663
// suggestion.
663
664
mem:: replace ( self , snapshot) ;
@@ -668,20 +669,16 @@ impl<'a> Parser<'a> {
668
669
// FIXME: actually check that the two expressions in the binop are
669
670
// paths and resynthesize new fn call expression instead of using
670
671
// `ExprKind::Err` placeholder.
671
- Ok ( Some ( self . mk_expr (
672
- lhs. span . to ( self . prev_span ) ,
673
- ExprKind :: Err ,
674
- ThinVec :: new ( ) ,
675
- ) ) )
672
+ mk_err_expr ( self , lhs. span . to ( self . prev_span ) )
676
673
}
677
674
} else {
678
675
// All we know is that this is `foo < bar >` and *nothing* else. Try to
679
676
// be helpful, but don't attempt to recover.
680
677
err. help ( TURBOFISH ) ;
681
678
err. help ( "or use `(...)` if you meant to specify fn arguments" ) ;
682
679
// These cases cause too many knock-down errors, bail out (#61329).
683
- }
684
- return Err ( err ) ;
680
+ Err ( err )
681
+ } ;
685
682
}
686
683
err. emit ( ) ;
687
684
}
@@ -1467,14 +1464,14 @@ impl<'a> Parser<'a> {
1467
1464
fn consume_tts (
1468
1465
& mut self ,
1469
1466
mut acc : i64 , // `i64` because malformed code can have more closing delims than opening.
1470
- modifier : & [ ( token :: TokenKind , i64 ) ] , // Not using `FxHashMap` and `FxHashSet` due to
1471
- early_return : & [ token:: TokenKind ] , // `token::TokenKind: !Eq + !Hash`.
1467
+ // Not using `FxHashMap` due to `token::TokenKind: !Eq + !Hash`.
1468
+ modifier : & [ ( token:: TokenKind , i64 ) ] ,
1472
1469
) {
1473
1470
while acc > 0 {
1474
1471
if let Some ( ( _, val) ) = modifier. iter ( ) . find ( |( t, _) | * t == self . token . kind ) {
1475
1472
acc += * val;
1476
1473
}
1477
- if self . token . kind == token:: Eof || early_return . contains ( & self . token . kind ) {
1474
+ if self . token . kind == token:: Eof {
1478
1475
break ;
1479
1476
}
1480
1477
self . bump ( ) ;
0 commit comments