Remove hir::Guard
Use Expr instead. Use `ExprKind::Let` to represent if let guards.
This commit is contained in:
parent
5113ed28ea
commit
407cb24142
17 changed files with 77 additions and 109 deletions
|
@ -1258,7 +1258,7 @@ pub struct Arm<'hir> {
|
|||
/// If this pattern and the optional guard matches, then `body` is evaluated.
|
||||
pub pat: &'hir Pat<'hir>,
|
||||
/// Optional guard clause.
|
||||
pub guard: Option<Guard<'hir>>,
|
||||
pub guard: Option<&'hir Expr<'hir>>,
|
||||
/// The expression the arm evaluates to if this arm matches.
|
||||
pub body: &'hir Expr<'hir>,
|
||||
}
|
||||
|
@ -1280,26 +1280,6 @@ pub struct Let<'hir> {
|
|||
pub is_recovered: Option<ErrorGuaranteed>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, HashStable_Generic)]
|
||||
pub enum Guard<'hir> {
|
||||
If(&'hir Expr<'hir>),
|
||||
IfLet(&'hir Let<'hir>),
|
||||
}
|
||||
|
||||
impl<'hir> Guard<'hir> {
|
||||
/// Returns the body of the guard
|
||||
///
|
||||
/// In other words, returns the e in either of the following:
|
||||
///
|
||||
/// - `if e`
|
||||
/// - `if let x = e`
|
||||
pub fn body(&self) -> &'hir Expr<'hir> {
|
||||
match self {
|
||||
Guard::If(e) | Guard::IfLet(Let { init: e, .. }) => e,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, HashStable_Generic)]
|
||||
pub struct ExprField<'hir> {
|
||||
#[stable_hasher(ignore)]
|
||||
|
|
|
@ -619,13 +619,8 @@ pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt<'v>) {
|
|||
pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm<'v>) {
|
||||
visitor.visit_id(arm.hir_id);
|
||||
visitor.visit_pat(arm.pat);
|
||||
if let Some(ref g) = arm.guard {
|
||||
match g {
|
||||
Guard::If(ref e) => visitor.visit_expr(e),
|
||||
Guard::IfLet(ref l) => {
|
||||
visitor.visit_let_expr(l);
|
||||
}
|
||||
}
|
||||
if let Some(ref e) = arm.guard {
|
||||
visitor.visit_expr(e);
|
||||
}
|
||||
visitor.visit_expr(arm.body);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue