@@ -327,7 +327,9 @@ impl<'a> Parser<'a> {
327327 this. parse_expr_assoc_with ( prec + prec_adjustment, LhsExpr :: NotYetParsed )
328328 } ) ?;
329329
330- let span = self . mk_expr_sp ( & lhs, lhs_span, rhs. span ) ;
330+ self . error_ambiguous_outer_attrs ( & lhs, lhs_span, rhs. span ) ;
331+ let span = lhs_span. to ( rhs. span ) ;
332+
331333 lhs = match op {
332334 AssocOp :: Add
333335 | AssocOp :: Subtract
@@ -426,6 +428,18 @@ impl<'a> Parser<'a> {
426428 } ) ;
427429 }
428430
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+
429443 /// Possibly translate the current token to an associative operator.
430444 /// The method does not advance the current token.
431445 ///
@@ -506,7 +520,8 @@ impl<'a> Parser<'a> {
506520 None
507521 } ;
508522 let rhs_span = rhs. as_ref ( ) . map_or ( cur_op_span, |x| x. span ) ;
509- let span = self . mk_expr_sp ( & lhs, lhs. span , rhs_span) ;
523+ self . error_ambiguous_outer_attrs ( & lhs, lhs. span , rhs_span) ;
524+ let span = lhs. span . to ( rhs_span) ;
510525 let limits =
511526 if op == AssocOp :: DotDot { RangeLimits :: HalfOpen } else { RangeLimits :: Closed } ;
512527 let range = self . mk_range ( Some ( lhs) , rhs, limits) ;
@@ -722,7 +737,8 @@ impl<'a> Parser<'a> {
722737 expr_kind : fn ( P < Expr > , P < Ty > ) -> ExprKind ,
723738 ) -> PResult < ' a , P < Expr > > {
724739 let mk_expr = |this : & mut Self , lhs : P < Expr > , rhs : P < Ty > | {
725- this. mk_expr ( this. mk_expr_sp ( & lhs, lhs_span, rhs. span ) , expr_kind ( lhs, rhs) )
740+ this. error_ambiguous_outer_attrs ( & lhs, lhs_span, rhs. span ) ;
741+ this. mk_expr ( lhs_span. to ( rhs. span ) , expr_kind ( lhs, rhs) )
726742 } ;
727743
728744 // Save the state of the parser before parsing type normally, in case there is a
@@ -3813,16 +3829,6 @@ impl<'a> Parser<'a> {
38133829 self . mk_expr ( span, ExprKind :: Err ( guar) )
38143830 }
38153831
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-
38263832 fn collect_tokens_for_expr (
38273833 & mut self ,
38283834 attrs : AttrWrapper ,
0 commit comments