@@ -327,9 +327,7 @@ impl<'a> Parser<'a> {
327
327
this. parse_expr_assoc_with ( prec + prec_adjustment, LhsExpr :: NotYetParsed )
328
328
} ) ?;
329
329
330
- self . error_ambiguous_outer_attrs ( & lhs, lhs_span, rhs. span ) ;
331
- let span = lhs_span. to ( rhs. span ) ;
332
-
330
+ let span = self . mk_expr_sp ( & lhs, lhs_span, rhs. span ) ;
333
331
lhs = match op {
334
332
AssocOp :: Add
335
333
| AssocOp :: Subtract
@@ -428,18 +426,6 @@ impl<'a> Parser<'a> {
428
426
} ) ;
429
427
}
430
428
431
- fn error_ambiguous_outer_attrs ( & self , lhs : & P < Expr > , lhs_span : Span , rhs_span : Span ) {
432
- if let Some ( attr) = lhs. attrs . iter ( ) . find ( |a| a. style == AttrStyle :: Outer ) {
433
- self . dcx ( ) . emit_err ( errors:: AmbiguousOuterAttributes {
434
- span : attr. span . to ( rhs_span) ,
435
- sugg : errors:: WrapInParentheses :: Expression {
436
- left : attr. span . shrink_to_lo ( ) ,
437
- right : lhs_span. shrink_to_hi ( ) ,
438
- } ,
439
- } ) ;
440
- }
441
- }
442
-
443
429
/// Possibly translate the current token to an associative operator.
444
430
/// The method does not advance the current token.
445
431
///
@@ -520,8 +506,7 @@ impl<'a> Parser<'a> {
520
506
None
521
507
} ;
522
508
let rhs_span = rhs. as_ref ( ) . map_or ( cur_op_span, |x| x. span ) ;
523
- self . error_ambiguous_outer_attrs ( & lhs, lhs. span , rhs_span) ;
524
- let span = lhs. span . to ( rhs_span) ;
509
+ let span = self . mk_expr_sp ( & lhs, lhs. span , rhs_span) ;
525
510
let limits =
526
511
if op == AssocOp :: DotDot { RangeLimits :: HalfOpen } else { RangeLimits :: Closed } ;
527
512
let range = self . mk_range ( Some ( lhs) , rhs, limits) ;
@@ -737,8 +722,7 @@ impl<'a> Parser<'a> {
737
722
expr_kind : fn ( P < Expr > , P < Ty > ) -> ExprKind ,
738
723
) -> PResult < ' a , P < Expr > > {
739
724
let mk_expr = |this : & mut Self , lhs : P < Expr > , rhs : P < Ty > | {
740
- this. error_ambiguous_outer_attrs ( & lhs, lhs_span, rhs. span ) ;
741
- this. mk_expr ( lhs_span. to ( rhs. span ) , expr_kind ( lhs, rhs) )
725
+ this. mk_expr ( this. mk_expr_sp ( & lhs, lhs_span, rhs. span ) , expr_kind ( lhs, rhs) )
742
726
} ;
743
727
744
728
// Save the state of the parser before parsing type normally, in case there is a
@@ -3829,6 +3813,16 @@ impl<'a> Parser<'a> {
3829
3813
self . mk_expr ( span, ExprKind :: Err ( guar) )
3830
3814
}
3831
3815
3816
+ /// Create expression span ensuring the span of the parent node
3817
+ /// is larger than the span of lhs and rhs, including the attributes.
3818
+ fn mk_expr_sp ( & self , lhs : & P < Expr > , lhs_span : Span , rhs_span : Span ) -> Span {
3819
+ lhs. attrs
3820
+ . iter ( )
3821
+ . find ( |a| a. style == AttrStyle :: Outer )
3822
+ . map_or ( lhs_span, |a| a. span )
3823
+ . to ( rhs_span)
3824
+ }
3825
+
3832
3826
fn collect_tokens_for_expr (
3833
3827
& mut self ,
3834
3828
attrs : AttrWrapper ,
0 commit comments