@@ -70,8 +70,8 @@ macro_rules! maybe_whole_expr {
7070
7171#[ derive( Debug ) ]
7272pub ( super ) enum LhsExpr {
73- // Already parsed either (a) nothing or (b) just the outer attributes.
74- Unparsed { attrs : Option < AttrWrapper > } ,
73+ // Already parsed just the outer attributes.
74+ Unparsed { attrs : AttrWrapper } ,
7575 // Already parsed the expression.
7676 Parsed { expr : P < Expr > , starts_statement : bool } ,
7777}
@@ -136,6 +136,7 @@ impl<'a> Parser<'a> {
136136 r : Restrictions ,
137137 attrs : Option < AttrWrapper > ,
138138 ) -> PResult < ' a , P < Expr > > {
139+ let attrs = self . parse_or_use_outer_attributes ( attrs) ?;
139140 self . with_res ( r, |this| this. parse_expr_assoc_with ( 0 , LhsExpr :: Unparsed { attrs } ) )
140141 }
141142
@@ -152,7 +153,6 @@ impl<'a> Parser<'a> {
152153 expr
153154 }
154155 LhsExpr :: Unparsed { attrs } => {
155- let attrs = self . parse_or_use_outer_attributes ( attrs) ?;
156156 if self . token . is_range_separator ( ) {
157157 return self . parse_expr_prefix_range ( attrs) ;
158158 } else {
@@ -295,10 +295,8 @@ impl<'a> Parser<'a> {
295295 Fixity :: None => 1 ,
296296 } ;
297297 let rhs = self . with_res ( restrictions - Restrictions :: STMT_EXPR , |this| {
298- this. parse_expr_assoc_with (
299- prec + prec_adjustment,
300- LhsExpr :: Unparsed { attrs : None } ,
301- )
298+ let attrs = this. parse_outer_attributes ( ) ?;
299+ this. parse_expr_assoc_with ( prec + prec_adjustment, LhsExpr :: Unparsed { attrs } )
302300 } ) ?;
303301
304302 let span = self . mk_expr_sp ( & lhs, lhs_span, rhs. span ) ;
@@ -471,8 +469,9 @@ impl<'a> Parser<'a> {
471469 ) -> PResult < ' a , P < Expr > > {
472470 let rhs = if self . is_at_start_of_range_notation_rhs ( ) {
473471 let maybe_lt = self . token . clone ( ) ;
472+ let attrs = self . parse_outer_attributes ( ) ?;
474473 Some (
475- self . parse_expr_assoc_with ( prec + 1 , LhsExpr :: Unparsed { attrs : None } )
474+ self . parse_expr_assoc_with ( prec + 1 , LhsExpr :: Unparsed { attrs } )
476475 . map_err ( |err| self . maybe_err_dotdotlt_syntax ( maybe_lt, err) ) ?,
477476 )
478477 } else {
@@ -528,9 +527,10 @@ impl<'a> Parser<'a> {
528527 this. bump ( ) ;
529528 let ( span, opt_end) = if this. is_at_start_of_range_notation_rhs ( ) {
530529 // RHS must be parsed with more associativity than the dots.
530+ let attrs = this. parse_outer_attributes ( ) ?;
531531 this. parse_expr_assoc_with (
532532 op. unwrap ( ) . precedence ( ) + 1 ,
533- LhsExpr :: Unparsed { attrs : None } ,
533+ LhsExpr :: Unparsed { attrs } ,
534534 )
535535 . map ( |x| ( lo. to ( x. span ) , Some ( x) ) )
536536 . map_err ( |err| this. maybe_err_dotdotlt_syntax ( maybe_lt, err) ) ?
@@ -2639,9 +2639,10 @@ impl<'a> Parser<'a> {
26392639 } else {
26402640 self . expect ( & token:: Eq ) ?;
26412641 }
2642+ let attrs = self . parse_outer_attributes ( ) ?;
26422643 let expr = self . parse_expr_assoc_with (
26432644 1 + prec_let_scrutinee_needs_par ( ) ,
2644- LhsExpr :: Unparsed { attrs : None } ,
2645+ LhsExpr :: Unparsed { attrs } ,
26452646 ) ?;
26462647 let span = lo. to ( expr. span ) ;
26472648 Ok ( self . mk_expr ( span, ExprKind :: Let ( pat, expr, span, recovered) ) )
0 commit comments