Skip to content

Commit 02d2cdf

Browse files
committed
Convert process_variant functions into closures.
It makes things a bit nicer.
1 parent b7855fa commit 02d2cdf

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

compiler/rustc_builtin_macros/src/deriving/clone.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,20 @@ fn cs_clone_shallow(
107107
substr: &Substructure<'_>,
108108
is_union: bool,
109109
) -> P<Expr> {
110-
fn process_variant(cx: &mut ExtCtxt<'_>, stmts: &mut Vec<ast::Stmt>, variant: &VariantData) {
110+
let mut stmts = Vec::new();
111+
let mut process_variant = |variant: &VariantData| {
111112
for field in variant.fields() {
112113
// let _: AssertParamIsClone<FieldTy>;
113114
super::assert_ty_bounds(
114115
cx,
115-
stmts,
116+
&mut stmts,
116117
field.ty.clone(),
117118
field.span,
118119
&[sym::clone, sym::AssertParamIsClone],
119120
);
120121
}
121-
}
122+
};
122123

123-
let mut stmts = Vec::new();
124124
if is_union {
125125
// let _: AssertParamIsCopy<Self>;
126126
let self_ty = cx.ty_path(cx.path_ident(trait_span, Ident::with_dummy_span(kw::SelfUpper)));
@@ -134,11 +134,11 @@ fn cs_clone_shallow(
134134
} else {
135135
match *substr.fields {
136136
StaticStruct(vdata, ..) => {
137-
process_variant(cx, &mut stmts, vdata);
137+
process_variant(vdata);
138138
}
139139
StaticEnum(enum_def, ..) => {
140140
for variant in &enum_def.variants {
141-
process_variant(cx, &mut stmts, &variant.data);
141+
process_variant(&variant.data);
142142
}
143143
}
144144
_ => cx.span_bug(

compiler/rustc_builtin_macros/src/deriving/cmp/eq.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -55,31 +55,27 @@ fn cs_total_eq_assert(
5555
trait_span: Span,
5656
substr: &Substructure<'_>,
5757
) -> P<Expr> {
58-
fn process_variant(
59-
cx: &mut ExtCtxt<'_>,
60-
stmts: &mut Vec<ast::Stmt>,
61-
variant: &ast::VariantData,
62-
) {
58+
let mut stmts = Vec::new();
59+
let mut process_variant = |variant: &ast::VariantData| {
6360
for field in variant.fields() {
6461
// let _: AssertParamIsEq<FieldTy>;
6562
super::assert_ty_bounds(
6663
cx,
67-
stmts,
64+
&mut stmts,
6865
field.ty.clone(),
6966
field.span,
7067
&[sym::cmp, sym::AssertParamIsEq],
7168
);
7269
}
73-
}
70+
};
7471

75-
let mut stmts = Vec::new();
7672
match *substr.fields {
7773
StaticStruct(vdata, ..) => {
78-
process_variant(cx, &mut stmts, vdata);
74+
process_variant(vdata);
7975
}
8076
StaticEnum(enum_def, ..) => {
8177
for variant in &enum_def.variants {
82-
process_variant(cx, &mut stmts, &variant.data);
78+
process_variant(&variant.data);
8379
}
8480
}
8581
_ => cx.span_bug(trait_span, "unexpected substructure in `derive(Eq)`"),

0 commit comments

Comments
 (0)