@@ -94,7 +94,8 @@ impl<'a> Parser<'a> {
9494 pub fn parse_expr ( & mut self ) -> PResult < ' a , P < Expr > > {
9595 self . current_closure . take ( ) ;
9696
97- self . parse_expr_res ( Restrictions :: empty ( ) , None )
97+ let attrs = self . parse_outer_attributes ( ) ?;
98+ self . parse_expr_res ( Restrictions :: empty ( ) , attrs)
9899 }
99100
100101 /// Parses an expression, forcing tokens to be collected
@@ -107,7 +108,8 @@ impl<'a> Parser<'a> {
107108 }
108109
109110 fn parse_expr_catch_underscore ( & mut self , restrictions : Restrictions ) -> PResult < ' a , P < Expr > > {
110- match self . parse_expr_res ( restrictions, None ) {
111+ let attrs = self . parse_outer_attributes ( ) ?;
112+ match self . parse_expr_res ( restrictions, attrs) {
111113 Ok ( expr) => Ok ( expr) ,
112114 Err ( err) => match self . token . ident ( ) {
113115 Some ( ( Ident { name : kw:: Underscore , .. } , IdentIsRaw :: No ) )
@@ -134,9 +136,8 @@ impl<'a> Parser<'a> {
134136 pub ( super ) fn parse_expr_res (
135137 & mut self ,
136138 r : Restrictions ,
137- attrs : Option < AttrWrapper > ,
139+ attrs : AttrWrapper ,
138140 ) -> PResult < ' a , P < Expr > > {
139- let attrs = self . parse_or_use_outer_attributes ( attrs) ?;
140141 self . with_res ( r, |this| this. parse_expr_assoc_with ( 0 , LhsExpr :: Unparsed { attrs } ) )
141142 }
142143
@@ -2343,7 +2344,8 @@ impl<'a> Parser<'a> {
23432344 self . restrictions - Restrictions :: STMT_EXPR - Restrictions :: ALLOW_LET ;
23442345 let prev = self . prev_token . clone ( ) ;
23452346 let token = self . token . clone ( ) ;
2346- match self . parse_expr_res ( restrictions, None ) {
2347+ let attrs = self . parse_outer_attributes ( ) ?;
2348+ match self . parse_expr_res ( restrictions, attrs) {
23472349 Ok ( expr) => expr,
23482350 Err ( err) => self . recover_closure_body ( err, before, prev, token, lo, decl_hi) ?,
23492351 }
@@ -2591,8 +2593,9 @@ impl<'a> Parser<'a> {
25912593
25922594 /// Parses the condition of a `if` or `while` expression.
25932595 fn parse_expr_cond ( & mut self ) -> PResult < ' a , P < Expr > > {
2596+ let attrs = self . parse_outer_attributes ( ) ?;
25942597 let mut cond =
2595- self . parse_expr_res ( Restrictions :: NO_STRUCT_LITERAL | Restrictions :: ALLOW_LET , None ) ?;
2598+ self . parse_expr_res ( Restrictions :: NO_STRUCT_LITERAL | Restrictions :: ALLOW_LET , attrs ) ?;
25962599
25972600 CondChecker :: new ( self ) . visit_expr ( & mut cond) ;
25982601
@@ -2776,7 +2779,8 @@ impl<'a> Parser<'a> {
27762779 ( Err ( err) , Some ( ( start_span, left) ) ) if self . eat_keyword ( kw:: In ) => {
27772780 // We know for sure we have seen `for ($SOMETHING in`. In the happy path this would
27782781 // happen right before the return of this method.
2779- let expr = match self . parse_expr_res ( Restrictions :: NO_STRUCT_LITERAL , None ) {
2782+ let attrs = self . parse_outer_attributes ( ) ?;
2783+ let expr = match self . parse_expr_res ( Restrictions :: NO_STRUCT_LITERAL , attrs) {
27802784 Ok ( expr) => expr,
27812785 Err ( expr_err) => {
27822786 // We don't know what followed the `in`, so cancel and bubble up the
@@ -2810,7 +2814,8 @@ impl<'a> Parser<'a> {
28102814 self . error_missing_in_for_loop ( ) ;
28112815 }
28122816 self . check_for_for_in_in_typo ( self . prev_token . span ) ;
2813- let expr = self . parse_expr_res ( Restrictions :: NO_STRUCT_LITERAL , None ) ?;
2817+ let attrs = self . parse_outer_attributes ( ) ?;
2818+ let expr = self . parse_expr_res ( Restrictions :: NO_STRUCT_LITERAL , attrs) ?;
28142819 Ok ( ( pat, expr) )
28152820 }
28162821
@@ -2922,7 +2927,8 @@ impl<'a> Parser<'a> {
29222927 /// Parses a `match ... { ... }` expression (`match` token already eaten).
29232928 fn parse_expr_match ( & mut self ) -> PResult < ' a , P < Expr > > {
29242929 let match_span = self . prev_token . span ;
2925- let scrutinee = self . parse_expr_res ( Restrictions :: NO_STRUCT_LITERAL , None ) ?;
2930+ let attrs = self . parse_outer_attributes ( ) ?;
2931+ let scrutinee = self . parse_expr_res ( Restrictions :: NO_STRUCT_LITERAL , attrs) ?;
29262932
29272933 self . parse_match_block ( match_span, match_span, scrutinee, MatchKind :: Prefix )
29282934 }
@@ -3126,8 +3132,9 @@ impl<'a> Parser<'a> {
31263132 let arrow_span = this. prev_token . span ;
31273133 let arm_start_span = this. token . span ;
31283134
3135+ let attrs = this. parse_outer_attributes ( ) ?;
31293136 let expr =
3130- this. parse_expr_res ( Restrictions :: STMT_EXPR , None ) . map_err ( |mut err| {
3137+ this. parse_expr_res ( Restrictions :: STMT_EXPR , attrs ) . map_err ( |mut err| {
31313138 err. span_label ( arrow_span, "while parsing the `match` arm starting here" ) ;
31323139 err
31333140 } ) ?;
@@ -3332,7 +3339,8 @@ impl<'a> Parser<'a> {
33323339 }
33333340
33343341 fn parse_match_guard_condition ( & mut self ) -> PResult < ' a , P < Expr > > {
3335- self . parse_expr_res ( Restrictions :: ALLOW_LET | Restrictions :: IN_IF_GUARD , None ) . map_err (
3342+ let attrs = self . parse_outer_attributes ( ) ?;
3343+ self . parse_expr_res ( Restrictions :: ALLOW_LET | Restrictions :: IN_IF_GUARD , attrs) . map_err (
33363344 |mut err| {
33373345 if self . prev_token == token:: OpenDelim ( Delimiter :: Brace ) {
33383346 let sugg_sp = self . prev_token . span . shrink_to_lo ( ) ;
0 commit comments