mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Make LhsExpr::AlreadyParsed
a named struct
This commit is contained in:
parent
5ca6f7d2c3
commit
ecb1ad11d9
@ -83,7 +83,7 @@ macro_rules! maybe_whole_expr {
|
|||||||
pub(super) enum LhsExpr {
|
pub(super) enum LhsExpr {
|
||||||
NotYetParsed,
|
NotYetParsed,
|
||||||
AttributesParsed(AttrWrapper),
|
AttributesParsed(AttrWrapper),
|
||||||
AlreadyParsed(P<Expr>, bool), // (expr, starts_statement)
|
AlreadyParsed { expr: P<Expr>, starts_statement: bool },
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Option<AttrWrapper>> for LhsExpr {
|
impl From<Option<AttrWrapper>> for LhsExpr {
|
||||||
@ -97,11 +97,11 @@ impl From<Option<AttrWrapper>> for LhsExpr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl From<P<Expr>> for LhsExpr {
|
impl From<P<Expr>> for LhsExpr {
|
||||||
/// Converts the `expr: P<Expr>` into `LhsExpr::AlreadyParsed(expr)`.
|
/// Converts the `expr: P<Expr>` into `LhsExpr::AlreadyParsed { expr, starts_statement: false }`.
|
||||||
///
|
///
|
||||||
/// This conversion does not allocate.
|
/// This conversion does not allocate.
|
||||||
fn from(expr: P<Expr>) -> Self {
|
fn from(expr: P<Expr>) -> Self {
|
||||||
LhsExpr::AlreadyParsed(expr, false)
|
LhsExpr::AlreadyParsed { expr, starts_statement: false }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,7 +174,7 @@ impl<'a> Parser<'a> {
|
|||||||
lhs: LhsExpr,
|
lhs: LhsExpr,
|
||||||
) -> PResult<'a, P<Expr>> {
|
) -> PResult<'a, P<Expr>> {
|
||||||
let mut starts_stmt = false;
|
let mut starts_stmt = false;
|
||||||
let mut lhs = if let LhsExpr::AlreadyParsed(expr, starts_statement) = lhs {
|
let mut lhs = if let LhsExpr::AlreadyParsed { expr, starts_statement } = lhs {
|
||||||
starts_stmt = starts_statement;
|
starts_stmt = starts_statement;
|
||||||
expr
|
expr
|
||||||
} else {
|
} else {
|
||||||
|
@ -164,7 +164,10 @@ impl<'a> Parser<'a> {
|
|||||||
// Perform this outside of the `collect_tokens_trailing_token` closure,
|
// Perform this outside of the `collect_tokens_trailing_token` closure,
|
||||||
// since our outer attributes do not apply to this part of the expression
|
// since our outer attributes do not apply to this part of the expression
|
||||||
let expr = self.with_res(Restrictions::STMT_EXPR, |this| {
|
let expr = self.with_res(Restrictions::STMT_EXPR, |this| {
|
||||||
this.parse_assoc_expr_with(0, LhsExpr::AlreadyParsed(expr, true))
|
this.parse_assoc_expr_with(
|
||||||
|
0,
|
||||||
|
LhsExpr::AlreadyParsed { expr, starts_statement: true },
|
||||||
|
)
|
||||||
})?;
|
})?;
|
||||||
Ok(self.mk_stmt(lo.to(self.prev_token.span), StmtKind::Expr(expr)))
|
Ok(self.mk_stmt(lo.to(self.prev_token.span), StmtKind::Expr(expr)))
|
||||||
} else {
|
} else {
|
||||||
@ -198,7 +201,10 @@ impl<'a> Parser<'a> {
|
|||||||
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_dot_or_call_expr_with(e, lo, attrs)?;
|
let e = self.parse_dot_or_call_expr_with(e, lo, attrs)?;
|
||||||
let e = self.parse_assoc_expr_with(0, LhsExpr::AlreadyParsed(e, false))?;
|
let e = self.parse_assoc_expr_with(
|
||||||
|
0,
|
||||||
|
LhsExpr::AlreadyParsed { expr: e, starts_statement: false },
|
||||||
|
)?;
|
||||||
StmtKind::Expr(e)
|
StmtKind::Expr(e)
|
||||||
};
|
};
|
||||||
Ok(self.mk_stmt(lo.to(hi), kind))
|
Ok(self.mk_stmt(lo.to(hi), kind))
|
||||||
|
Loading…
Reference in New Issue
Block a user