@@ -327,9 +327,7 @@ impl<'a> Parser<'a> {
327327 this. parse_expr_assoc_with ( prec + prec_adjustment, LhsExpr :: NotYetParsed )
328328 } ) ?;
329329
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 ) ;
333331 lhs = match op {
334332 AssocOp :: Add
335333 | AssocOp :: Subtract
@@ -428,18 +426,6 @@ impl<'a> Parser<'a> {
428426 } ) ;
429427 }
430428
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-
443429 /// Possibly translate the current token to an associative operator.
444430 /// The method does not advance the current token.
445431 ///
@@ -520,8 +506,7 @@ impl<'a> Parser<'a> {
520506 None
521507 } ;
522508 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) ;
525510 let limits =
526511 if op == AssocOp :: DotDot { RangeLimits :: HalfOpen } else { RangeLimits :: Closed } ;
527512 let range = self . mk_range ( Some ( lhs) , rhs, limits) ;
@@ -737,8 +722,7 @@ impl<'a> Parser<'a> {
737722 expr_kind : fn ( P < Expr > , P < Ty > ) -> ExprKind ,
738723 ) -> PResult < ' a , P < Expr > > {
739724 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) )
742726 } ;
743727
744728 // Save the state of the parser before parsing type normally, in case there is a
@@ -3829,6 +3813,16 @@ impl<'a> Parser<'a> {
38293813 self . mk_expr ( span, ExprKind :: Err ( guar) )
38303814 }
38313815
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+
38323826 fn collect_tokens_for_expr (
38333827 & mut self ,
38343828 attrs : AttrWrapper ,
0 commit comments