diff options
author | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-06-22 16:38:04 +1000 |
---|---|---|
committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-06-27 08:14:09 +1000 |
commit | 02d2cdfc288c4ef8f041f66bc207ad3087b3cbac (patch) | |
tree | a169c628db36dc4265bd178f2e3bdd167278c9fa | |
parent | b7855fa9defc918aa513edd021f4100a46c30109 (diff) | |
download | rust-02d2cdfc288c4ef8f041f66bc207ad3087b3cbac.tar.gz |
Convert `process_variant` functions into closures.
It makes things a bit nicer.
-rw-r--r-- | compiler/rustc_builtin_macros/src/deriving/clone.rs | 12 | ||||
-rw-r--r-- | compiler/rustc_builtin_macros/src/deriving/cmp/eq.rs | 16 |
2 files changed, 12 insertions, 16 deletions
diff --git a/compiler/rustc_builtin_macros/src/deriving/clone.rs b/compiler/rustc_builtin_macros/src/deriving/clone.rs index ce07081cc63..83317106990 100644 --- a/compiler/rustc_builtin_macros/src/deriving/clone.rs +++ b/compiler/rustc_builtin_macros/src/deriving/clone.rs @@ -107,20 +107,20 @@ fn cs_clone_shallow( substr: &Substructure<'_>, is_union: bool, ) -> 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() { // let _: AssertParamIsClone<FieldTy>; super::assert_ty_bounds( cx, - stmts, + &mut stmts, field.ty.clone(), field.span, &[sym::clone, sym::AssertParamIsClone], ); } - } + }; - let mut stmts = Vec::new(); if is_union { // let _: AssertParamIsCopy<Self>; 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 { match *substr.fields { StaticStruct(vdata, ..) => { - process_variant(cx, &mut stmts, vdata); + process_variant(vdata); } StaticEnum(enum_def, ..) => { for variant in &enum_def.variants { - process_variant(cx, &mut stmts, &variant.data); + process_variant(&variant.data); } } _ => cx.span_bug( diff --git a/compiler/rustc_builtin_macros/src/deriving/cmp/eq.rs b/compiler/rustc_builtin_macros/src/deriving/cmp/eq.rs index 440508ac280..f54ded3c87c 100644 --- a/compiler/rustc_builtin_macros/src/deriving/cmp/eq.rs +++ b/compiler/rustc_builtin_macros/src/deriving/cmp/eq.rs @@ -55,31 +55,27 @@ fn cs_total_eq_assert( trait_span: Span, substr: &Substructure<'_>, ) -> P<Expr> { - fn process_variant( - cx: &mut ExtCtxt<'_>, - stmts: &mut Vec<ast::Stmt>, - variant: &ast::VariantData, - ) { + let mut stmts = Vec::new(); + let mut process_variant = |variant: &ast::VariantData| { for field in variant.fields() { // let _: AssertParamIsEq<FieldTy>; super::assert_ty_bounds( cx, - stmts, + &mut stmts, field.ty.clone(), field.span, &[sym::cmp, sym::AssertParamIsEq], ); } - } + }; - let mut stmts = Vec::new(); match *substr.fields { StaticStruct(vdata, ..) => { - process_variant(cx, &mut stmts, vdata); + process_variant(vdata); } StaticEnum(enum_def, ..) => { 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)`"), |