lowering: move {lower_arm,arm} -> expr.rs

This commit is contained in:
Mazdak Farrokhzad
2019-08-10 17:48:09 +02:00
parent 93570b02bd
commit 7f522155dd
2 changed files with 29 additions and 25 deletions
-25
View File
@@ -1316,20 +1316,6 @@ fn lower_token(&mut self, token: Token) -> TokenStream {
}
}
fn lower_arm(&mut self, arm: &Arm) -> hir::Arm {
hir::Arm {
hir_id: self.next_id(),
attrs: self.lower_attrs(&arm.attrs),
pats: arm.pats.iter().map(|x| self.lower_pat(x)).collect(),
guard: match arm.guard {
Some(ref x) => Some(hir::Guard::If(P(self.lower_expr(x)))),
_ => None,
},
body: P(self.lower_expr(&arm.body)),
span: arm.span,
}
}
/// Given an associated type constraint like one of these:
///
/// ```
@@ -4472,17 +4458,6 @@ fn lower_trait_bound_modifier(&mut self, f: TraitBoundModifier) -> hir::TraitBou
// Helper methods for building HIR.
fn arm(&mut self, pats: hir::HirVec<P<hir::Pat>>, expr: P<hir::Expr>) -> hir::Arm {
hir::Arm {
hir_id: self.next_id(),
attrs: hir_vec![],
pats,
guard: None,
span: expr.span,
body: expr,
}
}
fn stmt(&mut self, span: Span, node: hir::StmtKind) -> hir::Stmt {
hir::Stmt { span, node, hir_id: self.next_id() }
}
+29
View File
@@ -436,6 +436,20 @@ fn wrap_in_try_constructor(
P(self.expr_call(e.span, from_err, hir_vec![e]))
}
fn lower_arm(&mut self, arm: &Arm) -> hir::Arm {
hir::Arm {
hir_id: self.next_id(),
attrs: self.lower_attrs(&arm.attrs),
pats: arm.pats.iter().map(|x| self.lower_pat(x)).collect(),
guard: match arm.guard {
Some(ref x) => Some(hir::Guard::If(P(self.lower_expr(x)))),
_ => None,
},
body: P(self.lower_expr(&arm.body)),
span: arm.span,
}
}
pub(super) fn make_async_expr(
&mut self,
capture_clause: CaptureBy,
@@ -1180,6 +1194,10 @@ fn lower_expr_try(&mut self, span: Span, sub_expr: &Expr) -> hir::ExprKind {
)
}
// =========================================================================
// Helper methods for building HIR.
// =========================================================================
/// Constructs a `true` or `false` literal expression.
pub(super) fn expr_bool(&mut self, span: Span, val: bool) -> hir::Expr {
let lit = Spanned { span, node: LitKind::Bool(val) };
@@ -1360,4 +1378,15 @@ fn field(&mut self, ident: Ident, expr: P<hir::Expr>, span: Span) -> hir::Field
is_shorthand: false,
}
}
fn arm(&mut self, pats: hir::HirVec<P<hir::Pat>>, expr: P<hir::Expr>) -> hir::Arm {
hir::Arm {
hir_id: self.next_id(),
attrs: hir_vec![],
pats,
guard: None,
span: expr.span,
body: expr,
}
}
}