@@ -40,14 +40,6 @@ use super::{
4040} ;
4141use crate :: { errors, maybe_recover_from_interpolated_ty_qpath} ;
4242
43- #[ derive( Debug ) ]
44- pub ( super ) enum LhsExpr {
45- // Already parsed just the outer attributes.
46- Unparsed { attrs : AttrWrapper } ,
47- // Already parsed the expression.
48- Parsed { expr : P < Expr > , starts_statement : bool } ,
49- }
50-
5143#[ derive( Debug ) ]
5244enum DestructuredFloat {
5345 /// 1e2
@@ -113,30 +105,31 @@ impl<'a> Parser<'a> {
113105 r : Restrictions ,
114106 attrs : AttrWrapper ,
115107 ) -> PResult < ' a , P < Expr > > {
116- self . with_res ( r, |this| this. parse_expr_assoc_with ( 0 , LhsExpr :: Unparsed { attrs } ) )
108+ self . with_res ( r, |this| this. parse_expr_assoc_with ( 0 , attrs) )
117109 }
118110
119111 /// Parses an associative expression with operators of at least `min_prec` precedence.
120112 pub ( super ) fn parse_expr_assoc_with (
121113 & mut self ,
122114 min_prec : usize ,
123- lhs : LhsExpr ,
115+ attrs : AttrWrapper ,
124116 ) -> PResult < ' a , P < Expr > > {
125- let mut starts_stmt = false ;
126- let mut lhs = match lhs {
127- LhsExpr :: Parsed { expr, starts_statement } => {
128- starts_stmt = starts_statement;
129- expr
130- }
131- LhsExpr :: Unparsed { attrs } => {
132- if self . token . is_range_separator ( ) {
133- return self . parse_expr_prefix_range ( attrs) ;
134- } else {
135- self . parse_expr_prefix ( attrs) ?
136- }
137- }
117+ let lhs = if self . token . is_range_separator ( ) {
118+ return self . parse_expr_prefix_range ( attrs) ;
119+ } else {
120+ self . parse_expr_prefix ( attrs) ?
138121 } ;
122+ self . parse_expr_assoc_rest_with ( min_prec, false , lhs)
123+ }
139124
125+ /// Parses the rest of an associative expression (i.e. the part after the lhs) with operators
126+ /// of at least `min_prec` precedence.
127+ pub ( super ) fn parse_expr_assoc_rest_with (
128+ & mut self ,
129+ min_prec : usize ,
130+ starts_stmt : bool ,
131+ mut lhs : P < Expr > ,
132+ ) -> PResult < ' a , P < Expr > > {
140133 if !self . should_continue_as_assoc_expr ( & lhs) {
141134 return Ok ( lhs) ;
142135 }
@@ -272,7 +265,7 @@ impl<'a> Parser<'a> {
272265 } ;
273266 let rhs = self . with_res ( restrictions - Restrictions :: STMT_EXPR , |this| {
274267 let attrs = this. parse_outer_attributes ( ) ?;
275- this. parse_expr_assoc_with ( prec + prec_adjustment, LhsExpr :: Unparsed { attrs } )
268+ this. parse_expr_assoc_with ( prec + prec_adjustment, attrs)
276269 } ) ?;
277270
278271 let span = self . mk_expr_sp ( & lhs, lhs_span, rhs. span ) ;
@@ -447,7 +440,7 @@ impl<'a> Parser<'a> {
447440 let maybe_lt = self . token . clone ( ) ;
448441 let attrs = self . parse_outer_attributes ( ) ?;
449442 Some (
450- self . parse_expr_assoc_with ( prec + 1 , LhsExpr :: Unparsed { attrs } )
443+ self . parse_expr_assoc_with ( prec + 1 , attrs)
451444 . map_err ( |err| self . maybe_err_dotdotlt_syntax ( maybe_lt, err) ) ?,
452445 )
453446 } else {
@@ -504,12 +497,9 @@ impl<'a> Parser<'a> {
504497 let ( span, opt_end) = if this. is_at_start_of_range_notation_rhs ( ) {
505498 // RHS must be parsed with more associativity than the dots.
506499 let attrs = this. parse_outer_attributes ( ) ?;
507- this. parse_expr_assoc_with (
508- op. unwrap ( ) . precedence ( ) + 1 ,
509- LhsExpr :: Unparsed { attrs } ,
510- )
511- . map ( |x| ( lo. to ( x. span ) , Some ( x) ) )
512- . map_err ( |err| this. maybe_err_dotdotlt_syntax ( maybe_lt, err) ) ?
500+ this. parse_expr_assoc_with ( op. unwrap ( ) . precedence ( ) + 1 , attrs)
501+ . map ( |x| ( lo. to ( x. span ) , Some ( x) ) )
502+ . map_err ( |err| this. maybe_err_dotdotlt_syntax ( maybe_lt, err) ) ?
513503 } else {
514504 ( lo, None )
515505 } ;
@@ -2645,10 +2635,7 @@ impl<'a> Parser<'a> {
26452635 self . expect ( & token:: Eq ) ?;
26462636 }
26472637 let attrs = self . parse_outer_attributes ( ) ?;
2648- let expr = self . parse_expr_assoc_with (
2649- 1 + prec_let_scrutinee_needs_par ( ) ,
2650- LhsExpr :: Unparsed { attrs } ,
2651- ) ?;
2638+ let expr = self . parse_expr_assoc_with ( 1 + prec_let_scrutinee_needs_par ( ) , attrs) ?;
26522639 let span = lo. to ( expr. span ) ;
26532640 Ok ( self . mk_expr ( span, ExprKind :: Let ( pat, expr, span, recovered) ) )
26542641 }
0 commit comments