@@ -694,7 +694,6 @@ impl<'a> Parser<'a> {
694
694
695
695
fn parse_dot_or_call_expr_with_ ( & mut self , e0 : P < Expr > , lo : Span ) -> PResult < ' a , P < Expr > > {
696
696
let mut e = e0;
697
- let mut hi;
698
697
loop {
699
698
// expr?
700
699
while self . eat ( & token:: Question ) {
@@ -766,23 +765,21 @@ impl<'a> Parser<'a> {
766
765
} ) ;
767
766
e = self . recover_seq_parse_error ( token:: Paren , lo, seq) ;
768
767
}
769
-
770
- // expr[...]
771
- // Could be either an index expression or a slicing expression.
772
- token:: OpenDelim ( token:: Bracket ) => {
773
- self . bump ( ) ;
774
- let ix = self . parse_expr ( ) ?;
775
- hi = self . token . span ;
776
- self . expect ( & token:: CloseDelim ( token:: Bracket ) ) ?;
777
- let index = self . mk_index ( e, ix) ;
778
- e = self . mk_expr ( lo. to ( hi) , index, AttrVec :: new ( ) )
779
- }
768
+ token:: OpenDelim ( token:: Bracket ) => e = self . parse_index_expr ( lo, e) ?,
780
769
_ => return Ok ( e) ,
781
770
}
782
771
}
783
772
return Ok ( e) ;
784
773
}
785
774
775
+ /// Parse an indexing expression `expr[...]`.
776
+ fn parse_index_expr ( & mut self , lo : Span , base : P < Expr > ) -> PResult < ' a , P < Expr > > {
777
+ self . bump ( ) ; // `[`
778
+ let index = self . parse_expr ( ) ?;
779
+ self . expect ( & token:: CloseDelim ( token:: Bracket ) ) ?;
780
+ Ok ( self . mk_expr ( lo. to ( self . prev_span ) , self . mk_index ( base, index) , AttrVec :: new ( ) ) )
781
+ }
782
+
786
783
/// Assuming we have just parsed `.`, continue parsing into an expression.
787
784
fn parse_dot_suffix ( & mut self , self_arg : P < Expr > , lo : Span ) -> PResult < ' a , P < Expr > > {
788
785
if self . token . span . rust_2018 ( ) && self . eat_keyword ( kw:: Await ) {
@@ -792,25 +789,22 @@ impl<'a> Parser<'a> {
792
789
let segment = self . parse_path_segment ( PathStyle :: Expr ) ?;
793
790
self . check_trailing_angle_brackets ( & segment, token:: OpenDelim ( token:: Paren ) ) ;
794
791
795
- Ok ( match self . token . kind {
796
- token:: OpenDelim ( token:: Paren ) => {
797
- // Method call `expr.f()`
798
- let mut args = self . parse_paren_expr_seq ( ) ?;
799
- args. insert ( 0 , self_arg) ;
792
+ if self . check ( & token:: OpenDelim ( token:: Paren ) ) {
793
+ // Method call `expr.f()`
794
+ let mut args = self . parse_paren_expr_seq ( ) ?;
795
+ args. insert ( 0 , self_arg) ;
800
796
801
- let span = lo. to ( self . prev_span ) ;
802
- self . mk_expr ( span, ExprKind :: MethodCall ( segment, args) , AttrVec :: new ( ) )
797
+ let span = lo. to ( self . prev_span ) ;
798
+ Ok ( self . mk_expr ( span, ExprKind :: MethodCall ( segment, args) , AttrVec :: new ( ) ) )
799
+ } else {
800
+ // Field access `expr.f`
801
+ if let Some ( args) = segment. args {
802
+ self . span_err ( args. span ( ) , "field expressions may not have generic arguments" ) ;
803
803
}
804
- _ => {
805
- // Field access `expr.f`
806
- if let Some ( args) = segment. args {
807
- self . span_err ( args. span ( ) , "field expressions may not have generic arguments" ) ;
808
- }
809
804
810
- let span = lo. to ( self . prev_span ) ;
811
- self . mk_expr ( span, ExprKind :: Field ( self_arg, segment. ident ) , AttrVec :: new ( ) )
812
- }
813
- } )
805
+ let span = lo. to ( self . prev_span ) ;
806
+ Ok ( self . mk_expr ( span, ExprKind :: Field ( self_arg, segment. ident ) , AttrVec :: new ( ) ) )
807
+ }
814
808
}
815
809
816
810
/// At the bottom (top?) of the precedence hierarchy,
0 commit comments