Skip to content

Commit 42e47df

Browse files
committed
Remove From impls for LhsExpr.
The `Option<AttrWrapper>` one maps to the first two variants, and the `P<Expr>` one maps to the third. Weird. The code is shorter and clearer without them.
1 parent 1c28229 commit 42e47df

File tree

2 files changed

+10
-25
lines changed

2 files changed

+10
-25
lines changed

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -75,25 +75,6 @@ pub(super) enum LhsExpr {
7575
AlreadyParsed { expr: P<Expr>, starts_statement: bool },
7676
}
7777

78-
impl From<Option<AttrWrapper>> for LhsExpr {
79-
/// Converts `Some(attrs)` into `LhsExpr::AttributesParsed(attrs)`
80-
/// and `None` into `LhsExpr::NotYetParsed`.
81-
///
82-
/// This conversion does not allocate.
83-
fn from(o: Option<AttrWrapper>) -> Self {
84-
if let Some(attrs) = o { LhsExpr::AttributesParsed(attrs) } else { LhsExpr::NotYetParsed }
85-
}
86-
}
87-
88-
impl From<P<Expr>> for LhsExpr {
89-
/// Converts the `expr: P<Expr>` into `LhsExpr::AlreadyParsed { expr, starts_statement: false }`.
90-
///
91-
/// This conversion does not allocate.
92-
fn from(expr: P<Expr>) -> Self {
93-
LhsExpr::AlreadyParsed { expr, starts_statement: false }
94-
}
95-
}
96-
9778
#[derive(Debug)]
9879
enum DestructuredFloat {
9980
/// 1e2
@@ -166,7 +147,11 @@ impl<'a> Parser<'a> {
166147
&mut self,
167148
already_parsed_attrs: Option<AttrWrapper>,
168149
) -> PResult<'a, P<Expr>> {
169-
self.parse_expr_assoc_with(0, already_parsed_attrs.into())
150+
let lhs = match already_parsed_attrs {
151+
Some(attrs) => LhsExpr::AttributesParsed(attrs),
152+
None => LhsExpr::NotYetParsed,
153+
};
154+
self.parse_expr_assoc_with(0, lhs)
170155
}
171156

172157
/// Parses an associative expression with operators of at least `min_prec` precedence.
@@ -2660,7 +2645,8 @@ impl<'a> Parser<'a> {
26602645
} else {
26612646
self.expect(&token::Eq)?;
26622647
}
2663-
let expr = self.parse_expr_assoc_with(1 + prec_let_scrutinee_needs_par(), None.into())?;
2648+
let expr =
2649+
self.parse_expr_assoc_with(1 + prec_let_scrutinee_needs_par(), LhsExpr::NotYetParsed)?;
26642650
let span = lo.to(expr.span);
26652651
Ok(self.mk_expr(span, ExprKind::Let(pat, expr, span, recovered)))
26662652
}

compiler/rustc_parse/src/parser/pat.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::errors::{
1010
UnexpectedParenInRangePatSugg, UnexpectedVertVertBeforeFunctionParam,
1111
UnexpectedVertVertInPattern,
1212
};
13-
use crate::parser::expr::could_be_unclosed_char_literal;
13+
use crate::parser::expr::{could_be_unclosed_char_literal, LhsExpr};
1414
use crate::{maybe_recover_from_interpolated_ty_qpath, maybe_whole};
1515
use rustc_ast::mut_visit::{noop_visit_pat, MutVisitor};
1616
use rustc_ast::ptr::P;
@@ -398,9 +398,8 @@ impl<'a> Parser<'a> {
398398

399399
// Parse an associative expression such as `+ expr`, `% expr`, ...
400400
// Assignements, ranges and `|` are disabled by [`Restrictions::IS_PAT`].
401-
if let Ok(expr) =
402-
snapshot.parse_expr_assoc_with(0, expr.into()).map_err(|err| err.cancel())
403-
{
401+
let lhs = LhsExpr::AlreadyParsed { expr, starts_statement: false };
402+
if let Ok(expr) = snapshot.parse_expr_assoc_with(0, lhs).map_err(|err| err.cancel()) {
404403
// We got a valid expression.
405404
self.restore_snapshot(snapshot);
406405
self.restrictions.remove(Restrictions::IS_PAT);

0 commit comments

Comments
 (0)