@@ -152,10 +152,10 @@ impl<'a> Parser<'a> {
152
152
expr
153
153
}
154
154
LhsExpr :: Unparsed { attrs } => {
155
+ let attrs = self . parse_or_use_outer_attributes ( attrs) ?;
155
156
if self . token . is_range_separator ( ) {
156
157
return self . parse_expr_prefix_range ( attrs) ;
157
158
} else {
158
- let attrs = self . parse_or_use_outer_attributes ( attrs) ?;
159
159
self . parse_expr_prefix ( attrs) ?
160
160
}
161
161
}
@@ -499,7 +499,12 @@ impl<'a> Parser<'a> {
499
499
}
500
500
501
501
/// Parses prefix-forms of range notation: `..expr`, `..`, `..=expr`.
502
- fn parse_expr_prefix_range ( & mut self , attrs : Option < AttrWrapper > ) -> PResult < ' a , P < Expr > > {
502
+ fn parse_expr_prefix_range ( & mut self , attrs : AttrWrapper ) -> PResult < ' a , P < Expr > > {
503
+ if !attrs. is_empty ( ) {
504
+ let err = errors:: DotDotRangeAttribute { span : self . token . span } ;
505
+ self . dcx ( ) . emit_err ( err) ;
506
+ }
507
+
503
508
// Check for deprecated `...` syntax.
504
509
if self . token == token:: DotDotDot {
505
510
self . err_dotdotdot_syntax ( self . token . span ) ;
@@ -516,11 +521,7 @@ impl<'a> Parser<'a> {
516
521
_ => RangeLimits :: Closed ,
517
522
} ;
518
523
let op = AssocOp :: from_token ( & self . token ) ;
519
- // FIXME: `parse_prefix_range_expr` is called when the current
520
- // token is `DotDot`, `DotDotDot`, or `DotDotEq`. If we haven't already
521
- // parsed attributes, then trying to parse them here will always fail.
522
- // We should figure out how we want attributes on range expressions to work.
523
- let attrs = self . parse_or_use_outer_attributes ( attrs) ?;
524
+ let attrs = self . parse_outer_attributes ( ) ?;
524
525
self . collect_tokens_for_expr ( attrs, |this, attrs| {
525
526
let lo = this. token . span ;
526
527
let maybe_lt = this. look_ahead ( 1 , |t| t. clone ( ) ) ;
@@ -871,10 +872,10 @@ impl<'a> Parser<'a> {
871
872
let has_lifetime = self . token . is_lifetime ( ) && self . look_ahead ( 1 , |t| t != & token:: Colon ) ;
872
873
let lifetime = has_lifetime. then ( || self . expect_lifetime ( ) ) ; // For recovery, see below.
873
874
let ( borrow_kind, mutbl) = self . parse_borrow_modifiers ( lo) ;
875
+ let attrs = self . parse_outer_attributes ( ) ?;
874
876
let expr = if self . token . is_range_separator ( ) {
875
- self . parse_expr_prefix_range ( None )
877
+ self . parse_expr_prefix_range ( attrs )
876
878
} else {
877
- let attrs = self . parse_outer_attributes ( ) ?;
878
879
self . parse_expr_prefix ( attrs)
879
880
} ?;
880
881
let hi = self . interpolated_or_expr_span ( & expr) ;
0 commit comments