@@ -94,7 +94,8 @@ impl<'a> Parser<'a> {
94
94
pub fn parse_expr ( & mut self ) -> PResult < ' a , P < Expr > > {
95
95
self . current_closure . take ( ) ;
96
96
97
- self . parse_expr_res ( Restrictions :: empty ( ) , None )
97
+ let attrs = self . parse_outer_attributes ( ) ?;
98
+ self . parse_expr_res ( Restrictions :: empty ( ) , attrs)
98
99
}
99
100
100
101
/// Parses an expression, forcing tokens to be collected
@@ -107,7 +108,8 @@ impl<'a> Parser<'a> {
107
108
}
108
109
109
110
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) {
111
113
Ok ( expr) => Ok ( expr) ,
112
114
Err ( err) => match self . token . ident ( ) {
113
115
Some ( ( Ident { name : kw:: Underscore , .. } , IdentIsRaw :: No ) )
@@ -134,9 +136,8 @@ impl<'a> Parser<'a> {
134
136
pub ( super ) fn parse_expr_res (
135
137
& mut self ,
136
138
r : Restrictions ,
137
- attrs : Option < AttrWrapper > ,
139
+ attrs : AttrWrapper ,
138
140
) -> PResult < ' a , P < Expr > > {
139
- let attrs = self . parse_or_use_outer_attributes ( attrs) ?;
140
141
self . with_res ( r, |this| this. parse_expr_assoc_with ( 0 , LhsExpr :: Unparsed { attrs } ) )
141
142
}
142
143
@@ -2343,7 +2344,8 @@ impl<'a> Parser<'a> {
2343
2344
self . restrictions - Restrictions :: STMT_EXPR - Restrictions :: ALLOW_LET ;
2344
2345
let prev = self . prev_token . clone ( ) ;
2345
2346
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) {
2347
2349
Ok ( expr) => expr,
2348
2350
Err ( err) => self . recover_closure_body ( err, before, prev, token, lo, decl_hi) ?,
2349
2351
}
@@ -2591,8 +2593,9 @@ impl<'a> Parser<'a> {
2591
2593
2592
2594
/// Parses the condition of a `if` or `while` expression.
2593
2595
fn parse_expr_cond ( & mut self ) -> PResult < ' a , P < Expr > > {
2596
+ let attrs = self . parse_outer_attributes ( ) ?;
2594
2597
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 ) ?;
2596
2599
2597
2600
CondChecker :: new ( self ) . visit_expr ( & mut cond) ;
2598
2601
@@ -2776,7 +2779,8 @@ impl<'a> Parser<'a> {
2776
2779
( Err ( err) , Some ( ( start_span, left) ) ) if self . eat_keyword ( kw:: In ) => {
2777
2780
// We know for sure we have seen `for ($SOMETHING in`. In the happy path this would
2778
2781
// 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) {
2780
2784
Ok ( expr) => expr,
2781
2785
Err ( expr_err) => {
2782
2786
// We don't know what followed the `in`, so cancel and bubble up the
@@ -2810,7 +2814,8 @@ impl<'a> Parser<'a> {
2810
2814
self . error_missing_in_for_loop ( ) ;
2811
2815
}
2812
2816
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) ?;
2814
2819
Ok ( ( pat, expr) )
2815
2820
}
2816
2821
@@ -2922,7 +2927,8 @@ impl<'a> Parser<'a> {
2922
2927
/// Parses a `match ... { ... }` expression (`match` token already eaten).
2923
2928
fn parse_expr_match ( & mut self ) -> PResult < ' a , P < Expr > > {
2924
2929
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) ?;
2926
2932
2927
2933
self . parse_match_block ( match_span, match_span, scrutinee, MatchKind :: Prefix )
2928
2934
}
@@ -3126,8 +3132,9 @@ impl<'a> Parser<'a> {
3126
3132
let arrow_span = this. prev_token . span ;
3127
3133
let arm_start_span = this. token . span ;
3128
3134
3135
+ let attrs = this. parse_outer_attributes ( ) ?;
3129
3136
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| {
3131
3138
err. span_label ( arrow_span, "while parsing the `match` arm starting here" ) ;
3132
3139
err
3133
3140
} ) ?;
@@ -3332,7 +3339,8 @@ impl<'a> Parser<'a> {
3332
3339
}
3333
3340
3334
3341
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 (
3336
3344
|mut err| {
3337
3345
if self . prev_token == token:: OpenDelim ( Delimiter :: Brace ) {
3338
3346
let sugg_sp = self . prev_token . span . shrink_to_lo ( ) ;
0 commit comments