introduce Guard enum

This commit is contained in:
F001
2018-08-30 12:18:11 +08:00
parent 70c33bb8e2
commit 7a083ca25f
22 changed files with 115 additions and 35 deletions

View File

@@ -117,6 +117,10 @@ pub trait Folder : Sized {
noop_fold_arm(a, self)
}
fn fold_guard(&mut self, g: Guard) -> Guard {
noop_fold_guard(g, self)
}
fn fold_pat(&mut self, p: P<Pat>) -> P<Pat> {
noop_fold_pat(p, self)
}
@@ -353,11 +357,17 @@ pub fn noop_fold_arm<T: Folder>(Arm {attrs, pats, guard, body}: Arm,
Arm {
attrs: fold_attrs(attrs, fld),
pats: pats.move_map(|x| fld.fold_pat(x)),
guard: guard.map(|x| fld.fold_expr(x)),
guard: guard.map(|x| fld.fold_guard(x)),
body: fld.fold_expr(body),
}
}
pub fn noop_fold_guard<T: Folder>(g: Guard, fld: &mut T) -> Guard {
match g {
Guard::If(e) => Guard::If(fld.fold_expr(e)),
}
}
pub fn noop_fold_ty_binding<T: Folder>(b: TypeBinding, fld: &mut T) -> TypeBinding {
TypeBinding {
id: fld.new_id(b.id),