Skip to content
Myr

Fix creating and filling a collections that was not read

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Mingun · committed by Mingun · parent 85c73ef · Browse files · 2 files+31 added−19 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+31 added−19 removed

  • tests:+24 added−8 removed
  • other:+7 added−11 removed

2 files+31 added−19 removed

modified:serde_derive/src/de.rs+7 added-11 removed
279 unmodified lines
280 deserialize_try_from(type_try_from)281 } else if let attr::Identifier::No = cont.attrs.identifier() {282 match &cont.data {283 Data::Enum(variants) => deserialize_enum(params, variants, &cont.attrs),284 Data::Struct(Style::Struct, fields) => deserialize_struct(285 params,286 fields,287 &cont.attrs,288 cont.attrs.has_flatten(),289 StructForm::Struct,290 ),284 Data::Struct(Style::Struct, fields) => {285 deserialize_struct(params, fields, &cont.attrs, StructForm::Struct)286 }287 Data::Struct(Style::Tuple, fields) | Data::Struct(Style::Newtype, fields) => {288 deserialize_tuple(289 params,290 fields,
631 unmodified lines
922fn deserialize_struct(923 params: &Parameters,924 fields: &[Field],925 cattrs: &attr::Container,930 has_flatten: bool,926 form: StructForm,927) -> Fragment {928 let this_type = &params.this_type;929 let this_value = &params.this_value;
40 unmodified lines
970 field.attrs.aliases(),971 )972 })973 .collect();974975 let has_flatten = fields976 .iter()977 .any(|field| field.attrs.flatten() && !field.attrs.skip_deserializing());978 let field_visitor = deserialize_field_identifier(&field_names_idents, cattrs, has_flatten);979980 // untagged struct variants do not get a visit_seq method. The same applies to981 // structs that only have a map representation.
854 unmodified lines
1836 Style::Struct => deserialize_struct(1837 params,1838 &variant.fields,1839 cattrs,1841 variant.attrs.has_flatten(),1840 StructForm::ExternallyTagged(variant_ident),1841 ),1842 }1843}
35 unmodified lines
1879 Style::Struct => deserialize_struct(1880 params,1881 &variant.fields,1882 cattrs,1885 variant.attrs.has_flatten(),1883 StructForm::InternallyTagged(variant_ident, deserializer),1884 ),1885 Style::Tuple => unreachable!("checked in serde_derive_internals"),1886 }
49 unmodified lines
1936 Style::Struct => deserialize_struct(1937 params,1938 &variant.fields,1939 cattrs,1943 variant.attrs.has_flatten(),1940 StructForm::Untagged(variant_ident, deserializer),1941 ),1942 }1943}
1232 unmodified lines
modified:test_suite/tests/test_gen.rs+24 added-8 removed
546 unmodified lines
547 }548 assert::<FlattenWith>();549550 #[derive(Serialize, Deserialize)]551 pub struct Flatten<T> {552 #[serde(flatten)]553 t: T,554 }555556 #[derive(Serialize, Deserialize)]557 #[serde(deny_unknown_fields)]558 pub struct FlattenDenyUnknown<T> {559 #[serde(flatten)]560 t: T,561 }562563 #[derive(Serialize, Deserialize)]564 pub struct SkipDeserializing<T> {565 #[serde(skip_deserializing)]566 flat: T,567 }568569 #[derive(Serialize, Deserialize)]570 #[serde(deny_unknown_fields)]571 pub struct SkipDeserializingDenyUnknown<T> {572 #[serde(skip_deserializing)]573 flat: T,574 }575576 #[derive(Serialize, Deserialize)]577 pub struct StaticStrStruct<'a> {578 a: &'a str,579 b: &'static str,580 }
157 unmodified lines
738 #[serde(flatten, skip_serializing_if = "StdOption::is_none")]739 flat: StdOption<T>,740 }741723 #[allow(clippy::collection_is_never_read)] // FIXME724 const _: () = {725 #[derive(Serialize, Deserialize)]726 pub struct FlattenSkipDeserializing<T> {727 #[serde(flatten, skip_deserializing)]728 flat: T,729 }742 #[derive(Serialize, Deserialize)]743 pub struct FlattenSkipDeserializing<T> {744 #[serde(flatten, skip_deserializing)]745 flat: T,746 }730 };747748 #[derive(Serialize, Deserialize)]749 #[serde(untagged)]750 pub enum Inner<T> {
202 unmodified lines