mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
or-patterns: syntax: adjust derive, format, and building.
This commit is contained in:
parent
424492acc8
commit
76625eb0cc
@ -537,9 +537,9 @@ impl<'a> ExtCtxt<'a> {
|
||||
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 @@ impl<'a> ExtCtxt<'a> {
|
||||
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 @@ impl<'a> ExtCtxt<'a> {
|
||||
}
|
||||
|
||||
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 @@ impl<'a> MethodDef<'a> {
|
||||
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 @@ impl<'a> MethodDef<'a> {
|
||||
nonself_args,
|
||||
&substructure);
|
||||
|
||||
cx.arm(sp, vec![single_pat], arm_expr)
|
||||
cx.arm(sp, single_pat, arm_expr)
|
||||
})
|
||||
.collect();
|
||||
|
||||
@ -1337,7 +1337,7 @@ impl<'a> MethodDef<'a> {
|
||||
_ => 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 @@ impl<'a, 'b> Context<'a, 'b> {
|
||||
// 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]);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user