From 81150f301e846e87b9420b2f9bebdf603d894c24 Mon Sep 17 00:00:00 2001 From: theguy147 <37738506+theguy147@users.noreply.github.com> Date: Mon, 10 Oct 2022 16:53:28 +0200 Subject: [PATCH] respect ignored fields for mutatable structs --- lain_derive/src/mutations.rs | 9 ++++++--- testsuite/src/lib.rs | 7 +++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lain_derive/src/mutations.rs b/lain_derive/src/mutations.rs index f378e48..5ad311d 100644 --- a/lain_derive/src/mutations.rs +++ b/lain_derive/src/mutations.rs @@ -271,13 +271,16 @@ fn mutatable_enum_visitor(variants: &[Variant], cont_ident: &syn::Ident) -> Vec< fn mutatable_struct_visitor(fields: &[Field]) -> Vec { fields .iter() - .map(|field| { + .filter_map(|field| { + if field.attrs.ignore() { + return None; + } let (_field_ident, _field_ident_string, initializer) = field_mutator(field, "self.", false); - quote! { + Some(quote! { #initializer - } + }) }) .collect() } diff --git a/testsuite/src/lib.rs b/testsuite/src/lib.rs index 78f1799..82c6c9f 100644 --- a/testsuite/src/lib.rs +++ b/testsuite/src/lib.rs @@ -169,7 +169,7 @@ mod test { #[test] fn test_ignored_fields() { - #[derive(NewFuzzed, BinarySerialize, Clone)] + #[derive(NewFuzzed, BinarySerialize, Clone, Mutatable)] struct IgnoredFieldsStruct { #[lain(ignore)] ignored: u8, @@ -177,9 +177,12 @@ mod test { let mut mutator = get_mutator(); - let initialized_struct = IgnoredFieldsStruct::new_fuzzed(&mut mutator, None); + let mut initialized_struct = IgnoredFieldsStruct::new_fuzzed(&mut mutator, None); assert_eq!(initialized_struct.ignored, 0); + + initialized_struct.mutate(&mut mutator, None); + assert_eq!(initialized_struct.ignored, 0); } #[test]