Auto merge of #53815 - F001:if-let-guard, r=petrochenkov

refactor match guard

This is the first step to implement RFC 2294: if-let-guard. Tracking issue: https://github.com/rust-lang/rust/issues/51114

The second step should be introducing another variant `IfLet` in the Guard enum. I separated them into 2 PRs for the convenience of reviewers.

r? @petrochenkov
This commit is contained in:
bors
2018-09-01 20:31:29 +00:00
22 changed files with 115 additions and 35 deletions

View File

@@ -118,6 +118,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)
}
@@ -354,11 +358,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),