@@ -328,9 +328,7 @@ impl<'a> Parser<'a> {
328
328
this. parse_expr_assoc_with ( prec + prec_adjustment, LhsExpr :: NotYetParsed )
329
329
} ) ?;
330
330
331
- self . error_ambiguous_outer_attrs ( & lhs, lhs_span, rhs. span ) ;
332
- let span = lhs_span. to ( rhs. span ) ;
333
-
331
+ let span = self . mk_expr_sp ( & lhs, lhs_span, rhs. span ) ;
334
332
lhs = match op {
335
333
AssocOp :: Add
336
334
| AssocOp :: Subtract
@@ -429,18 +427,6 @@ impl<'a> Parser<'a> {
429
427
} ) ;
430
428
}
431
429
432
- fn error_ambiguous_outer_attrs ( & self , lhs : & P < Expr > , lhs_span : Span , rhs_span : Span ) {
433
- if let Some ( attr) = lhs. attrs . iter ( ) . find ( |a| a. style == AttrStyle :: Outer ) {
434
- self . dcx ( ) . emit_err ( errors:: AmbiguousOuterAttributes {
435
- span : attr. span . to ( rhs_span) ,
436
- sugg : errors:: WrapInParentheses :: Expression {
437
- left : attr. span . shrink_to_lo ( ) ,
438
- right : lhs_span. shrink_to_hi ( ) ,
439
- } ,
440
- } ) ;
441
- }
442
- }
443
-
444
430
/// Possibly translate the current token to an associative operator.
445
431
/// The method does not advance the current token.
446
432
///
@@ -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) ;
@@ -739,8 +724,7 @@ impl<'a> Parser<'a> {
739
724
expr_kind : fn ( P < Expr > , P < Ty > ) -> ExprKind ,
740
725
) -> PResult < ' a , P < Expr > > {
741
726
let mk_expr = |this : & mut Self , lhs : P < Expr > , rhs : P < Ty > | {
742
- this. error_ambiguous_outer_attrs ( & lhs, lhs_span, rhs. span ) ;
743
- this. mk_expr ( lhs_span. to ( rhs. span ) , expr_kind ( lhs, rhs) )
727
+ this. mk_expr ( this. mk_expr_sp ( & lhs, lhs_span, rhs. span ) , expr_kind ( lhs, rhs) )
744
728
} ;
745
729
746
730
// Save the state of the parser before parsing type normally, in case there is a
@@ -3858,6 +3842,16 @@ impl<'a> Parser<'a> {
3858
3842
self . mk_expr ( span, ExprKind :: Err ( guar) )
3859
3843
}
3860
3844
3845
+ /// Create expression span ensuring the span of the parent node
3846
+ /// is larger than the span of lhs and rhs, including the attributes.
3847
+ fn mk_expr_sp ( & self , lhs : & P < Expr > , lhs_span : Span , rhs_span : Span ) -> Span {
3848
+ lhs. attrs
3849
+ . iter ( )
3850
+ . find ( |a| a. style == AttrStyle :: Outer )
3851
+ . map_or ( lhs_span, |a| a. span )
3852
+ . to ( rhs_span)
3853
+ }
3854
+
3861
3855
fn collect_tokens_for_expr (
3862
3856
& mut self ,
3863
3857
attrs : AttrWrapper ,
0 commit comments