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]