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
Provenance
- Commit
0647a7c- Tree
003af8f- Author
Mingun <Alexander_Sergey@mail.ru>- Committer
Mingun <Alexander_Sergey@mail.ru>- Parent
85c73ef
2 files changed+31 added−19 removed
modified:serde_derive/src/de.rs+7 added-11 removed
279 unmodified lines280 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 lines922 fn 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 = ¶ms.this_type;929 let this_value = ¶ms.this_value;40 unmodified lines970 field.attrs.aliases(),971 )972 })973 .collect();974+975+ 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);979 980 // untagged struct variants do not get a visit_seq method. The same applies to981 // structs that only have a map representation.854 unmodified lines1836 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 lines1879 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 lines1936 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 linesmodified:test_suite/tests/test_gen.rs+24 added-8 removed
546 unmodified lines547 }548 assert::<FlattenWith>();549 550 #[derive(Serialize, Deserialize)]551+ pub struct Flatten<T> {552+ #[serde(flatten)]553+ t: T,554+ }555+556+ #[derive(Serialize, Deserialize)]557 #[serde(deny_unknown_fields)]558 pub struct FlattenDenyUnknown<T> {559 #[serde(flatten)]560 t: T,561 }562 563 #[derive(Serialize, Deserialize)]564+ pub struct SkipDeserializing<T> {565+ #[serde(skip_deserializing)]566+ flat: T,567+ }568+569+ #[derive(Serialize, Deserialize)]570+ #[serde(deny_unknown_fields)]571+ pub struct SkipDeserializingDenyUnknown<T> {572+ #[serde(skip_deserializing)]573+ flat: T,574+ }575+576+ #[derive(Serialize, Deserialize)]577 pub struct StaticStrStruct<'a> {578 a: &'a str,579 b: &'static str,580 }157 unmodified lines738 #[serde(flatten, skip_serializing_if = "StdOption::is_none")]739 flat: StdOption<T>,740 }741 723- #[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- };747 748 #[derive(Serialize, Deserialize)]749 #[serde(untagged)]750 pub enum Inner<T> {202 unmodified lines