提交 76625eb0 编写于 作者: M Mazdak Farrokhzad

or-patterns: syntax: adjust derive, format, and building.

上级 424492ac
......@@ -537,9 +537,9 @@ pub fn expr_try(&self, sp: Span, head: P<ast::Expr>) -> P<ast::Expr> {
let err_expr = self.expr(sp, ast::ExprKind::Ret(Some(err_inner_expr)));
// `Ok(__try_var) => __try_var`
let ok_arm = self.arm(sp, vec![ok_pat], binding_expr);
let ok_arm = self.arm(sp, ok_pat, binding_expr);
// `Err(__try_var) => return Err(__try_var)`
let err_arm = self.arm(sp, vec![err_pat], err_expr);
let err_arm = self.arm(sp, err_pat, err_expr);
// `match head { Ok() => ..., Err() => ... }`
self.expr_match(sp, head, vec![ok_arm, err_arm])
......@@ -606,10 +606,10 @@ pub fn pat_err(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat> {
self.pat_tuple_struct(span, path, vec![pat])
}
pub fn arm(&self, span: Span, pats: Vec<P<ast::Pat>>, expr: P<ast::Expr>) -> ast::Arm {
pub fn arm(&self, span: Span, pat: P<ast::Pat>, expr: P<ast::Expr>) -> ast::Arm {
ast::Arm {
attrs: vec![],
pats,
pat,
guard: None,
body: expr,
span,
......@@ -618,7 +618,7 @@ pub fn arm(&self, span: Span, pats: Vec<P<ast::Pat>>, expr: P<ast::Expr>) -> ast
}
pub fn arm_unreachable(&self, span: Span) -> ast::Arm {
self.arm(span, vec![self.pat_wild(span)], self.expr_unreachable(span))
self.arm(span, self.pat_wild(span), self.expr_unreachable(span))
}
pub fn expr_match(&self, span: Span, arg: P<ast::Expr>, arms: Vec<ast::Arm>) -> P<Expr> {
......
......@@ -95,11 +95,9 @@ pub fn cs_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> P<
cx.expr_call_global(span, cmp_path.clone(), args)
};
let eq_arm = cx.arm(span,
vec![cx.pat_path(span, equals_path.clone())],
old);
let eq_arm = cx.arm(span, cx.pat_path(span, equals_path.clone()), old);
let neq_arm = cx.arm(span,
vec![cx.pat_ident(span, test_id)],
cx.pat_ident(span, test_id),
cx.expr_ident(span, test_id));
cx.expr_match(span, new, vec![eq_arm, neq_arm])
......
......@@ -160,10 +160,10 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_
};
let eq_arm = cx.arm(span,
vec![cx.pat_some(span, cx.pat_path(span, ordering.clone()))],
cx.pat_some(span, cx.pat_path(span, ordering.clone())),
old);
let neq_arm = cx.arm(span,
vec![cx.pat_ident(span, test_id)],
cx.pat_ident(span, test_id),
cx.expr_ident(span, test_id));
cx.expr_match(span, new, vec![eq_arm, neq_arm])
......
......@@ -119,9 +119,7 @@ fn decodable_substructure(cx: &mut ExtCtxt<'_>,
vec![idx, exprdecode.clone()]))
});
arms.push(cx.arm(v_span,
vec![cx.pat_lit(v_span, cx.expr_usize(v_span, i))],
decoded));
arms.push(cx.arm(v_span, cx.pat_lit(v_span, cx.expr_usize(v_span, i)), decoded));
}
arms.push(cx.arm_unreachable(trait_span));
......
......@@ -1071,7 +1071,7 @@ fn expand_struct_method_body<'b>(&self,
for (arg_expr, pat) in self_args.iter().zip(patterns) {
body = cx.expr_match(trait_.span,
arg_expr.clone(),
vec![cx.arm(trait_.span, vec![pat.clone()], body)])
vec![cx.arm(trait_.span, pat.clone(), body)])
}
body
......@@ -1311,7 +1311,7 @@ fn build_enum_match_tuple<'b>(&self,
nonself_args,
&substructure);
cx.arm(sp, vec![single_pat], arm_expr)
cx.arm(sp, single_pat, arm_expr)
})
.collect();
......@@ -1337,7 +1337,7 @@ fn build_enum_match_tuple<'b>(&self,
_ => None,
};
if let Some(arm) = default {
match_arms.push(cx.arm(sp, vec![cx.pat_wild(sp)], arm));
match_arms.push(cx.arm(sp, cx.pat_wild(sp), arm));
}
// We will usually need the catch-all after matching the
......
......@@ -716,7 +716,7 @@ fn into_expr(self) -> P<ast::Expr> {
// But the nested match expression is proved to perform not as well
// as series of let's; the first approach does.
let pat = self.ecx.pat_tuple(self.fmtsp, pats);
let arm = self.ecx.arm(self.fmtsp, vec![pat], args_array);
let arm = self.ecx.arm(self.fmtsp, pat, args_array);
let head = self.ecx.expr(self.fmtsp, ast::ExprKind::Tup(heads));
let result = self.ecx.expr_match(self.fmtsp, head, vec![arm]);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册