提交 5b6ddd50 编写于 作者: O Oli Scherer

Convert a closure into a method

上级 40334da7
......@@ -246,6 +246,18 @@ fn type_may_have_partial_eq_impl(&self, ty: Ty<'tcx>) -> bool {
})
}
fn field_pats(
&self,
vals: impl Iterator<Item = &'tcx ty::Const<'tcx>>,
) -> Result<Vec<FieldPat<'tcx>>, FallbackToConstRef> {
vals.enumerate()
.map(|(idx, val)| {
let field = Field::new(idx);
Ok(FieldPat { field, pattern: self.recur(val, false)? })
})
.collect()
}
// Recursive helper for `to_pat`; invoke that (instead of calling this directly).
fn recur(
&self,
......@@ -257,16 +269,6 @@ fn recur(
let tcx = self.tcx();
let param_env = self.param_env;
let field_pats = |vals: &[&'tcx ty::Const<'tcx>]| -> Result<_, _> {
vals.iter()
.enumerate()
.map(|(idx, val)| {
let field = Field::new(idx);
Ok(FieldPat { field, pattern: self.recur(val, false)? })
})
.collect()
};
let kind = match cv.ty.kind() {
ty::Float(_) => {
tcx.struct_span_lint_hir(
......@@ -361,12 +363,12 @@ fn recur(
variant_index: destructured
.variant
.expect("destructed const of adt without variant id"),
subpatterns: field_pats(destructured.fields)?,
subpatterns: self.field_pats(destructured.fields.iter().copied())?,
}
}
ty::Tuple(_) | ty::Adt(_, _) => {
let destructured = tcx.destructure_const(param_env.and(cv));
PatKind::Leaf { subpatterns: field_pats(destructured.fields)? }
PatKind::Leaf { subpatterns: self.field_pats(destructured.fields.iter().copied())? }
}
ty::Array(..) => PatKind::Array {
prefix: tcx
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册