Convert process_variant
functions into closures.
It makes things a bit nicer.
This commit is contained in:
parent
b7855fa9de
commit
02d2cdfc28
2 changed files with 12 additions and 16 deletions
|
@ -107,20 +107,20 @@ fn cs_clone_shallow(
|
||||||
substr: &Substructure<'_>,
|
substr: &Substructure<'_>,
|
||||||
is_union: bool,
|
is_union: bool,
|
||||||
) -> P<Expr> {
|
) -> P<Expr> {
|
||||||
fn process_variant(cx: &mut ExtCtxt<'_>, stmts: &mut Vec<ast::Stmt>, variant: &VariantData) {
|
let mut stmts = Vec::new();
|
||||||
|
let mut process_variant = |variant: &VariantData| {
|
||||||
for field in variant.fields() {
|
for field in variant.fields() {
|
||||||
// let _: AssertParamIsClone<FieldTy>;
|
// let _: AssertParamIsClone<FieldTy>;
|
||||||
super::assert_ty_bounds(
|
super::assert_ty_bounds(
|
||||||
cx,
|
cx,
|
||||||
stmts,
|
&mut stmts,
|
||||||
field.ty.clone(),
|
field.ty.clone(),
|
||||||
field.span,
|
field.span,
|
||||||
&[sym::clone, sym::AssertParamIsClone],
|
&[sym::clone, sym::AssertParamIsClone],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
let mut stmts = Vec::new();
|
|
||||||
if is_union {
|
if is_union {
|
||||||
// let _: AssertParamIsCopy<Self>;
|
// let _: AssertParamIsCopy<Self>;
|
||||||
let self_ty = cx.ty_path(cx.path_ident(trait_span, Ident::with_dummy_span(kw::SelfUpper)));
|
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(
|
||||||
} else {
|
} else {
|
||||||
match *substr.fields {
|
match *substr.fields {
|
||||||
StaticStruct(vdata, ..) => {
|
StaticStruct(vdata, ..) => {
|
||||||
process_variant(cx, &mut stmts, vdata);
|
process_variant(vdata);
|
||||||
}
|
}
|
||||||
StaticEnum(enum_def, ..) => {
|
StaticEnum(enum_def, ..) => {
|
||||||
for variant in &enum_def.variants {
|
for variant in &enum_def.variants {
|
||||||
process_variant(cx, &mut stmts, &variant.data);
|
process_variant(&variant.data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => cx.span_bug(
|
_ => cx.span_bug(
|
||||||
|
|
|
@ -55,31 +55,27 @@ fn cs_total_eq_assert(
|
||||||
trait_span: Span,
|
trait_span: Span,
|
||||||
substr: &Substructure<'_>,
|
substr: &Substructure<'_>,
|
||||||
) -> P<Expr> {
|
) -> P<Expr> {
|
||||||
fn process_variant(
|
let mut stmts = Vec::new();
|
||||||
cx: &mut ExtCtxt<'_>,
|
let mut process_variant = |variant: &ast::VariantData| {
|
||||||
stmts: &mut Vec<ast::Stmt>,
|
|
||||||
variant: &ast::VariantData,
|
|
||||||
) {
|
|
||||||
for field in variant.fields() {
|
for field in variant.fields() {
|
||||||
// let _: AssertParamIsEq<FieldTy>;
|
// let _: AssertParamIsEq<FieldTy>;
|
||||||
super::assert_ty_bounds(
|
super::assert_ty_bounds(
|
||||||
cx,
|
cx,
|
||||||
stmts,
|
&mut stmts,
|
||||||
field.ty.clone(),
|
field.ty.clone(),
|
||||||
field.span,
|
field.span,
|
||||||
&[sym::cmp, sym::AssertParamIsEq],
|
&[sym::cmp, sym::AssertParamIsEq],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
let mut stmts = Vec::new();
|
|
||||||
match *substr.fields {
|
match *substr.fields {
|
||||||
StaticStruct(vdata, ..) => {
|
StaticStruct(vdata, ..) => {
|
||||||
process_variant(cx, &mut stmts, vdata);
|
process_variant(vdata);
|
||||||
}
|
}
|
||||||
StaticEnum(enum_def, ..) => {
|
StaticEnum(enum_def, ..) => {
|
||||||
for variant in &enum_def.variants {
|
for variant in &enum_def.variants {
|
||||||
process_variant(cx, &mut stmts, &variant.data);
|
process_variant(&variant.data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => cx.span_bug(trait_span, "unexpected substructure in `derive(Eq)`"),
|
_ => cx.span_bug(trait_span, "unexpected substructure in `derive(Eq)`"),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue