@@ -40,14 +40,6 @@ use super::{
40
40
} ;
41
41
use crate :: { errors, maybe_recover_from_interpolated_ty_qpath} ;
42
42
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
-
51
43
#[ derive( Debug ) ]
52
44
enum DestructuredFloat {
53
45
/// 1e2
@@ -113,30 +105,31 @@ impl<'a> Parser<'a> {
113
105
r : Restrictions ,
114
106
attrs : AttrWrapper ,
115
107
) -> 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) )
117
109
}
118
110
119
111
/// Parses an associative expression with operators of at least `min_prec` precedence.
120
112
pub ( super ) fn parse_expr_assoc_with (
121
113
& mut self ,
122
114
min_prec : usize ,
123
- lhs : LhsExpr ,
115
+ attrs : AttrWrapper ,
124
116
) -> 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) ?
138
121
} ;
122
+ self . parse_expr_assoc_rest_with ( min_prec, false , lhs)
123
+ }
139
124
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 > > {
140
133
if !self . should_continue_as_assoc_expr ( & lhs) {
141
134
return Ok ( lhs) ;
142
135
}
@@ -272,7 +265,7 @@ impl<'a> Parser<'a> {
272
265
} ;
273
266
let rhs = self . with_res ( restrictions - Restrictions :: STMT_EXPR , |this| {
274
267
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)
276
269
} ) ?;
277
270
278
271
let span = self . mk_expr_sp ( & lhs, lhs_span, rhs. span ) ;
@@ -447,7 +440,7 @@ impl<'a> Parser<'a> {
447
440
let maybe_lt = self . token . clone ( ) ;
448
441
let attrs = self . parse_outer_attributes ( ) ?;
449
442
Some (
450
- self . parse_expr_assoc_with ( prec + 1 , LhsExpr :: Unparsed { attrs } )
443
+ self . parse_expr_assoc_with ( prec + 1 , attrs)
451
444
. map_err ( |err| self . maybe_err_dotdotlt_syntax ( maybe_lt, err) ) ?,
452
445
)
453
446
} else {
@@ -504,12 +497,9 @@ impl<'a> Parser<'a> {
504
497
let ( span, opt_end) = if this. is_at_start_of_range_notation_rhs ( ) {
505
498
// RHS must be parsed with more associativity than the dots.
506
499
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) ) ?
513
503
} else {
514
504
( lo, None )
515
505
} ;
@@ -2645,10 +2635,7 @@ impl<'a> Parser<'a> {
2645
2635
self . expect ( & token:: Eq ) ?;
2646
2636
}
2647
2637
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) ?;
2652
2639
let span = lo. to ( expr. span ) ;
2653
2640
Ok ( self . mk_expr ( span, ExprKind :: Let ( pat, expr, span, recovered) ) )
2654
2641
}
0 commit comments