@@ -328,9 +328,7 @@ impl<'a> Parser<'a> {
328328 this. parse_expr_assoc_with ( prec + prec_adjustment, LhsExpr :: NotYetParsed )
329329 } ) ?;
330330
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 ) ;
334332 lhs = match op {
335333 AssocOp :: Add
336334 | AssocOp :: Subtract
@@ -429,18 +427,6 @@ impl<'a> Parser<'a> {
429427 } ) ;
430428 }
431429
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-
444430 /// Possibly translate the current token to an associative operator.
445431 /// The method does not advance the current token.
446432 ///
@@ -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) ;
@@ -739,8 +724,7 @@ impl<'a> Parser<'a> {
739724 expr_kind : fn ( P < Expr > , P < Ty > ) -> ExprKind ,
740725 ) -> PResult < ' a , P < Expr > > {
741726 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) )
744728 } ;
745729
746730 // Save the state of the parser before parsing type normally, in case there is a
@@ -3858,6 +3842,16 @@ impl<'a> Parser<'a> {
38583842 self . mk_expr ( span, ExprKind :: Err ( guar) )
38593843 }
38603844
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+
38613855 fn collect_tokens_for_expr (
38623856 & mut self ,
38633857 attrs : AttrWrapper ,
0 commit comments