Skip to content

Commit ecb1ad1

Browse files
committed
Make LhsExpr::AlreadyParsed a named struct
1 parent 5ca6f7d commit ecb1ad1

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

compiler/rustc_parse/src/parser/expr.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ macro_rules! maybe_whole_expr {
8383
pub(super) enum LhsExpr {
8484
NotYetParsed,
8585
AttributesParsed(AttrWrapper),
86-
AlreadyParsed(P<Expr>, bool), // (expr, starts_statement)
86+
AlreadyParsed { expr: P<Expr>, starts_statement: bool },
8787
}
8888

8989
impl From<Option<AttrWrapper>> for LhsExpr {
@@ -97,11 +97,11 @@ impl From<Option<AttrWrapper>> for LhsExpr {
9797
}
9898

9999
impl From<P<Expr>> for LhsExpr {
100-
/// Converts the `expr: P<Expr>` into `LhsExpr::AlreadyParsed(expr)`.
100+
/// Converts the `expr: P<Expr>` into `LhsExpr::AlreadyParsed { expr, starts_statement: false }`.
101101
///
102102
/// This conversion does not allocate.
103103
fn from(expr: P<Expr>) -> Self {
104-
LhsExpr::AlreadyParsed(expr, false)
104+
LhsExpr::AlreadyParsed { expr, starts_statement: false }
105105
}
106106
}
107107

@@ -174,7 +174,7 @@ impl<'a> Parser<'a> {
174174
lhs: LhsExpr,
175175
) -> PResult<'a, P<Expr>> {
176176
let mut starts_stmt = false;
177-
let mut lhs = if let LhsExpr::AlreadyParsed(expr, starts_statement) = lhs {
177+
let mut lhs = if let LhsExpr::AlreadyParsed { expr, starts_statement } = lhs {
178178
starts_stmt = starts_statement;
179179
expr
180180
} else {

compiler/rustc_parse/src/parser/stmt.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,10 @@ impl<'a> Parser<'a> {
164164
// Perform this outside of the `collect_tokens_trailing_token` closure,
165165
// since our outer attributes do not apply to this part of the expression
166166
let expr = self.with_res(Restrictions::STMT_EXPR, |this| {
167-
this.parse_assoc_expr_with(0, LhsExpr::AlreadyParsed(expr, true))
167+
this.parse_assoc_expr_with(
168+
0,
169+
LhsExpr::AlreadyParsed { expr, starts_statement: true },
170+
)
168171
})?;
169172
Ok(self.mk_stmt(lo.to(self.prev_token.span), StmtKind::Expr(expr)))
170173
} else {
@@ -198,7 +201,10 @@ impl<'a> Parser<'a> {
198201
let e = self.mk_expr(lo.to(hi), ExprKind::MacCall(mac));
199202
let e = self.maybe_recover_from_bad_qpath(e)?;
200203
let e = self.parse_dot_or_call_expr_with(e, lo, attrs)?;
201-
let e = self.parse_assoc_expr_with(0, LhsExpr::AlreadyParsed(e, false))?;
204+
let e = self.parse_assoc_expr_with(
205+
0,
206+
LhsExpr::AlreadyParsed { expr: e, starts_statement: false },
207+
)?;
202208
StmtKind::Expr(e)
203209
};
204210
Ok(self.mk_stmt(lo.to(hi), kind))

0 commit comments

Comments
 (0)