@@ -703,20 +703,7 @@ impl<'a> Parser<'a> {
703
703
704
704
// expr.f
705
705
if self . eat ( & token:: Dot ) {
706
- match self . token . kind {
707
- token:: Ident ( ..) => {
708
- e = self . parse_dot_suffix ( e, lo) ?;
709
- }
710
- token:: Literal ( token:: Lit { kind : token:: Integer , symbol, suffix } ) => {
711
- e = self . parse_tuple_field_access_expr ( lo, e, symbol, suffix) ;
712
- }
713
- token:: Literal ( token:: Lit { kind : token:: Float , symbol, .. } ) => {
714
- if let Some ( err) = self . recover_field_access_by_float_lit ( lo, & e, symbol) {
715
- err?
716
- }
717
- }
718
- _ => self . error_unexpected_after_dot ( ) ,
719
- }
706
+ e = self . parse_dot_suffix_expr ( lo, e) ?;
720
707
continue ;
721
708
}
722
709
if self . expr_is_complete ( & e) {
@@ -731,6 +718,22 @@ impl<'a> Parser<'a> {
731
718
return Ok ( e) ;
732
719
}
733
720
721
+ fn parse_dot_suffix_expr ( & mut self , lo : Span , base : P < Expr > ) -> PResult < ' a , P < Expr > > {
722
+ match self . token . kind {
723
+ token:: Ident ( ..) => self . parse_dot_suffix ( base, lo) ,
724
+ token:: Literal ( token:: Lit { kind : token:: Integer , symbol, suffix } ) => {
725
+ Ok ( self . parse_tuple_field_access_expr ( lo, base, symbol, suffix) )
726
+ }
727
+ token:: Literal ( token:: Lit { kind : token:: Float , symbol, .. } ) => {
728
+ self . recover_field_access_by_float_lit ( lo, base, symbol)
729
+ }
730
+ _ => {
731
+ self . error_unexpected_after_dot ( ) ;
732
+ Ok ( base)
733
+ }
734
+ }
735
+ }
736
+
734
737
fn error_unexpected_after_dot ( & self ) {
735
738
// FIXME Could factor this out into non_fatal_unexpected or something.
736
739
let actual = self . this_token_to_string ( ) ;
@@ -740,9 +743,9 @@ impl<'a> Parser<'a> {
740
743
fn recover_field_access_by_float_lit (
741
744
& mut self ,
742
745
lo : Span ,
743
- base : & P < Expr > ,
746
+ base : P < Expr > ,
744
747
sym : Symbol ,
745
- ) -> Option < PResult < ' a , ( ) > > {
748
+ ) -> PResult < ' a , P < Expr > > {
746
749
self . bump ( ) ;
747
750
748
751
let fstr = sym. as_str ( ) ;
@@ -752,7 +755,13 @@ impl<'a> Parser<'a> {
752
755
err. span_label ( self . prev_span , "unexpected token" ) ;
753
756
754
757
if fstr. chars ( ) . all ( |x| "0123456789." . contains ( x) ) {
755
- let float = fstr. parse :: < f64 > ( ) . ok ( ) ?;
758
+ let float = match fstr. parse :: < f64 > ( ) {
759
+ Ok ( f) => f,
760
+ Err ( _) => {
761
+ err. emit ( ) ;
762
+ return Ok ( base) ;
763
+ }
764
+ } ;
756
765
let sugg = pprust:: to_string ( |s| {
757
766
s. popen ( ) ;
758
767
s. print_expr ( & base) ;
@@ -769,7 +778,7 @@ impl<'a> Parser<'a> {
769
778
Applicability :: MachineApplicable ,
770
779
) ;
771
780
}
772
- Some ( Err ( err) )
781
+ Err ( err)
773
782
}
774
783
775
784
fn parse_tuple_field_access_expr (
0 commit comments