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 { - fn process_variant(cx: &mut ExtCtxt<'_>, stmts: &mut Vec, variant: &VariantData) { + let mut stmts = Vec::new(); + let mut process_variant = |variant: &VariantData| { for field in variant.fields() { // let _: AssertParamIsClone; 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; 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 { - fn process_variant( - cx: &mut ExtCtxt<'_>, - stmts: &mut Vec, - variant: &ast::VariantData, - ) { + let mut stmts = Vec::new(); + let mut process_variant = |variant: &ast::VariantData| { for field in variant.fields() { // let _: AssertParamIsEq; 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)`"),