@@ -70,9 +70,10 @@ macro_rules! maybe_whole_expr {
7070
7171#[ derive( Debug ) ]
7272pub ( 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 } ,
7677}
7778
7879#[ derive( Debug ) ]
@@ -133,25 +134,18 @@ impl<'a> Parser<'a> {
133134 pub ( super ) fn parse_expr_res (
134135 & mut self ,
135136 r : Restrictions ,
136- already_parsed_attrs : Option < AttrWrapper > ,
137+ attrs : Option < AttrWrapper > ,
137138 ) -> 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 ) )
139140 }
140141
141142 /// Parses an associative expression.
142143 ///
143144 /// This parses an expression accounting for associativity and precedence of the operators in
144145 /// the expression.
145146 #[ 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 } )
155149 }
156150
157151 /// Parses an associative expression with operators of at least `min_prec` precedence.
@@ -161,18 +155,17 @@ impl<'a> Parser<'a> {
161155 lhs : LhsExpr ,
162156 ) -> PResult < ' a , P < Expr > > {
163157 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+ }
176169 }
177170 } ;
178171
@@ -310,7 +303,10 @@ impl<'a> Parser<'a> {
310303 Fixity :: None => 1 ,
311304 } ;
312305 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+ )
314310 } ) ?;
315311
316312 let span = self . mk_expr_sp ( & lhs, lhs_span, rhs. span ) ;
@@ -484,7 +480,7 @@ impl<'a> Parser<'a> {
484480 let rhs = if self . is_at_start_of_range_notation_rhs ( ) {
485481 let maybe_lt = self . token . clone ( ) ;
486482 Some (
487- self . parse_expr_assoc_with ( prec + 1 , LhsExpr :: NotYetParsed )
483+ self . parse_expr_assoc_with ( prec + 1 , LhsExpr :: Unparsed { attrs : None } )
488484 . map_err ( |err| self . maybe_err_dotdotlt_syntax ( maybe_lt, err) ) ?,
489485 )
490486 } else {
@@ -539,9 +535,12 @@ impl<'a> Parser<'a> {
539535 this. bump ( ) ;
540536 let ( span, opt_end) = if this. is_at_start_of_range_notation_rhs ( ) {
541537 // 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) ) ?
545544 } else {
546545 ( lo, None )
547546 } ;
@@ -2645,8 +2644,10 @@ impl<'a> Parser<'a> {
26452644 } else {
26462645 self . expect ( & token:: Eq ) ?;
26472646 }
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+ ) ?;
26502651 let span = lo. to ( expr. span ) ;
26512652 Ok ( self . mk_expr ( span, ExprKind :: Let ( pat, expr, span, recovered) ) )
26522653 }
0 commit comments