@@ -70,9 +70,10 @@ macro_rules! maybe_whole_expr {
70
70
71
71
#[ derive( Debug ) ]
72
72
pub ( super ) enum LhsExpr {
73
- NotYetParsed ,
74
- AttributesParsed ( AttrWrapper ) ,
75
- AlreadyParsed { expr : P < Expr > , starts_statement : bool } ,
73
+ // Already parsed either (a) nothing or (b) just the outer attributes.
74
+ Unparsed { attrs : Option < AttrWrapper > } ,
75
+ // Already parsed the expression.
76
+ Parsed { expr : P < Expr > , starts_statement : bool } ,
76
77
}
77
78
78
79
#[ derive( Debug ) ]
@@ -133,25 +134,18 @@ impl<'a> Parser<'a> {
133
134
pub ( super ) fn parse_expr_res (
134
135
& mut self ,
135
136
r : Restrictions ,
136
- already_parsed_attrs : Option < AttrWrapper > ,
137
+ attrs : Option < AttrWrapper > ,
137
138
) -> PResult < ' a , P < Expr > > {
138
- self . with_res ( r, |this| this. parse_expr_assoc ( already_parsed_attrs ) )
139
+ self . with_res ( r, |this| this. parse_expr_assoc ( attrs ) )
139
140
}
140
141
141
142
/// Parses an associative expression.
142
143
///
143
144
/// This parses an expression accounting for associativity and precedence of the operators in
144
145
/// the expression.
145
146
#[ inline]
146
- fn parse_expr_assoc (
147
- & mut self ,
148
- already_parsed_attrs : Option < AttrWrapper > ,
149
- ) -> PResult < ' a , P < Expr > > {
150
- let lhs = match already_parsed_attrs {
151
- Some ( attrs) => LhsExpr :: AttributesParsed ( attrs) ,
152
- None => LhsExpr :: NotYetParsed ,
153
- } ;
154
- self . parse_expr_assoc_with ( 0 , lhs)
147
+ fn parse_expr_assoc ( & mut self , attrs : Option < AttrWrapper > ) -> PResult < ' a , P < Expr > > {
148
+ self . parse_expr_assoc_with ( 0 , LhsExpr :: Unparsed { attrs } )
155
149
}
156
150
157
151
/// Parses an associative expression with operators of at least `min_prec` precedence.
@@ -161,18 +155,17 @@ impl<'a> Parser<'a> {
161
155
lhs : LhsExpr ,
162
156
) -> PResult < ' a , P < Expr > > {
163
157
let mut starts_stmt = false ;
164
- let mut lhs = if let LhsExpr :: AlreadyParsed { expr, starts_statement } = lhs {
165
- starts_stmt = starts_statement;
166
- expr
167
- } else {
168
- let attrs = match lhs {
169
- LhsExpr :: AttributesParsed ( attrs) => Some ( attrs) ,
170
- _ => None ,
171
- } ;
172
- if self . token . is_range_separator ( ) {
173
- return self . parse_expr_prefix_range ( attrs) ;
174
- } else {
175
- self . parse_expr_prefix ( attrs) ?
158
+ let mut lhs = match lhs {
159
+ LhsExpr :: Parsed { expr, starts_statement } => {
160
+ starts_stmt = starts_statement;
161
+ expr
162
+ }
163
+ LhsExpr :: Unparsed { attrs } => {
164
+ if self . token . is_range_separator ( ) {
165
+ return self . parse_expr_prefix_range ( attrs) ;
166
+ } else {
167
+ self . parse_expr_prefix ( attrs) ?
168
+ }
176
169
}
177
170
} ;
178
171
@@ -310,7 +303,10 @@ impl<'a> Parser<'a> {
310
303
Fixity :: None => 1 ,
311
304
} ;
312
305
let rhs = self . with_res ( restrictions - Restrictions :: STMT_EXPR , |this| {
313
- this. parse_expr_assoc_with ( prec + prec_adjustment, LhsExpr :: NotYetParsed )
306
+ this. parse_expr_assoc_with (
307
+ prec + prec_adjustment,
308
+ LhsExpr :: Unparsed { attrs : None } ,
309
+ )
314
310
} ) ?;
315
311
316
312
let span = self . mk_expr_sp ( & lhs, lhs_span, rhs. span ) ;
@@ -484,7 +480,7 @@ impl<'a> Parser<'a> {
484
480
let rhs = if self . is_at_start_of_range_notation_rhs ( ) {
485
481
let maybe_lt = self . token . clone ( ) ;
486
482
Some (
487
- self . parse_expr_assoc_with ( prec + 1 , LhsExpr :: NotYetParsed )
483
+ self . parse_expr_assoc_with ( prec + 1 , LhsExpr :: Unparsed { attrs : None } )
488
484
. map_err ( |err| self . maybe_err_dotdotlt_syntax ( maybe_lt, err) ) ?,
489
485
)
490
486
} else {
@@ -539,9 +535,12 @@ impl<'a> Parser<'a> {
539
535
this. bump ( ) ;
540
536
let ( span, opt_end) = if this. is_at_start_of_range_notation_rhs ( ) {
541
537
// RHS must be parsed with more associativity than the dots.
542
- this. parse_expr_assoc_with ( op. unwrap ( ) . precedence ( ) + 1 , LhsExpr :: NotYetParsed )
543
- . map ( |x| ( lo. to ( x. span ) , Some ( x) ) )
544
- . map_err ( |err| this. maybe_err_dotdotlt_syntax ( maybe_lt, err) ) ?
538
+ this. parse_expr_assoc_with (
539
+ op. unwrap ( ) . precedence ( ) + 1 ,
540
+ LhsExpr :: Unparsed { attrs : None } ,
541
+ )
542
+ . map ( |x| ( lo. to ( x. span ) , Some ( x) ) )
543
+ . map_err ( |err| this. maybe_err_dotdotlt_syntax ( maybe_lt, err) ) ?
545
544
} else {
546
545
( lo, None )
547
546
} ;
@@ -2645,8 +2644,10 @@ impl<'a> Parser<'a> {
2645
2644
} else {
2646
2645
self . expect ( & token:: Eq ) ?;
2647
2646
}
2648
- let expr =
2649
- self . parse_expr_assoc_with ( 1 + prec_let_scrutinee_needs_par ( ) , LhsExpr :: NotYetParsed ) ?;
2647
+ let expr = self . parse_expr_assoc_with (
2648
+ 1 + prec_let_scrutinee_needs_par ( ) ,
2649
+ LhsExpr :: Unparsed { attrs : None } ,
2650
+ ) ?;
2650
2651
let span = lo. to ( expr. span ) ;
2651
2652
Ok ( self . mk_expr ( span, ExprKind :: Let ( pat, expr, span, recovered) ) )
2652
2653
}
0 commit comments