Reorder Parser::parse_expr_dot_or_call_with arguments.

Put `attrs` before `e0` because that matches the order in the source
code, where outer attributes appear before expressions.
This commit is contained in:
Nicholas Nethercote 2024-07-16 15:54:34 +10:00
parent 48cdfc388d
commit d247489ac2
3 changed files with 5 additions and 5 deletions

View File

@ -885,15 +885,15 @@ impl<'a> Parser<'a> {
self.collect_tokens_for_expr(attrs, |this, attrs| { self.collect_tokens_for_expr(attrs, |this, attrs| {
let base = this.parse_expr_bottom()?; let base = this.parse_expr_bottom()?;
let span = this.interpolated_or_expr_span(&base); let span = this.interpolated_or_expr_span(&base);
this.parse_expr_dot_or_call_with(base, span, attrs) this.parse_expr_dot_or_call_with(attrs, base, span)
}) })
} }
pub(super) fn parse_expr_dot_or_call_with( pub(super) fn parse_expr_dot_or_call_with(
&mut self, &mut self,
mut attrs: ast::AttrVec,
e0: P<Expr>, e0: P<Expr>,
lo: Span, lo: Span,
mut attrs: ast::AttrVec,
) -> PResult<'a, P<Expr>> { ) -> PResult<'a, P<Expr>> {
// Stitch the list of outer attributes onto the return value. // Stitch the list of outer attributes onto the return value.
// A little bit ugly, but the best way given the current code // A little bit ugly, but the best way given the current code

View File

@ -388,9 +388,9 @@ impl<'a> Parser<'a> {
// Parse `?`, `.f`, `(arg0, arg1, ...)` or `[expr]` until they've all been eaten. // Parse `?`, `.f`, `(arg0, arg1, ...)` or `[expr]` until they've all been eaten.
if let Ok(expr) = snapshot if let Ok(expr) = snapshot
.parse_expr_dot_or_call_with( .parse_expr_dot_or_call_with(
AttrVec::new(),
self.mk_expr(pat_span, ExprKind::Dummy), // equivalent to transforming the parsed pattern into an `Expr` self.mk_expr(pat_span, ExprKind::Dummy), // equivalent to transforming the parsed pattern into an `Expr`
pat_span, pat_span,
AttrVec::new(),
) )
.map_err(|err| err.cancel()) .map_err(|err| err.cancel())
{ {

View File

@ -164,7 +164,7 @@ impl<'a> Parser<'a> {
}; };
let expr = this.with_res(Restrictions::STMT_EXPR, |this| { let expr = this.with_res(Restrictions::STMT_EXPR, |this| {
this.parse_expr_dot_or_call_with(expr, lo, attrs) this.parse_expr_dot_or_call_with(attrs, expr, lo)
})?; })?;
// `DUMMY_SP` will get overwritten later in this function // `DUMMY_SP` will get overwritten later in this function
Ok((this.mk_stmt(rustc_span::DUMMY_SP, StmtKind::Expr(expr)), TrailingToken::None)) Ok((this.mk_stmt(rustc_span::DUMMY_SP, StmtKind::Expr(expr)), TrailingToken::None))
@ -206,7 +206,7 @@ impl<'a> Parser<'a> {
// Since none of the above applied, this is an expression statement macro. // Since none of the above applied, this is an expression statement macro.
let e = self.mk_expr(lo.to(hi), ExprKind::MacCall(mac)); let e = self.mk_expr(lo.to(hi), ExprKind::MacCall(mac));
let e = self.maybe_recover_from_bad_qpath(e)?; let e = self.maybe_recover_from_bad_qpath(e)?;
let e = self.parse_expr_dot_or_call_with(e, lo, attrs)?; let e = self.parse_expr_dot_or_call_with(attrs, e, lo)?;
let e = self let e = self
.parse_expr_assoc_with(0, LhsExpr::Parsed { expr: e, starts_statement: false })?; .parse_expr_assoc_with(0, LhsExpr::Parsed { expr: e, starts_statement: false })?;
StmtKind::Expr(e) StmtKind::Expr(e)