Fix creating and filling a collections that was not read
This commit is contained in:
parent
85c73ef8de
commit
0647a7c1fe
@ -281,13 +281,9 @@ fn deserialize_body(cont: &Container, params: &Parameters) -> Fragment {
|
||||
} else if let attr::Identifier::No = cont.attrs.identifier() {
|
||||
match &cont.data {
|
||||
Data::Enum(variants) => deserialize_enum(params, variants, &cont.attrs),
|
||||
Data::Struct(Style::Struct, fields) => deserialize_struct(
|
||||
params,
|
||||
fields,
|
||||
&cont.attrs,
|
||||
cont.attrs.has_flatten(),
|
||||
StructForm::Struct,
|
||||
),
|
||||
Data::Struct(Style::Struct, fields) => {
|
||||
deserialize_struct(params, fields, &cont.attrs, StructForm::Struct)
|
||||
}
|
||||
Data::Struct(Style::Tuple, fields) | Data::Struct(Style::Newtype, fields) => {
|
||||
deserialize_tuple(
|
||||
params,
|
||||
@ -927,7 +923,6 @@ fn deserialize_struct(
|
||||
params: &Parameters,
|
||||
fields: &[Field],
|
||||
cattrs: &attr::Container,
|
||||
has_flatten: bool,
|
||||
form: StructForm,
|
||||
) -> Fragment {
|
||||
let this_type = ¶ms.this_type;
|
||||
@ -976,6 +971,10 @@ fn deserialize_struct(
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
|
||||
let has_flatten = fields
|
||||
.iter()
|
||||
.any(|field| field.attrs.flatten() && !field.attrs.skip_deserializing());
|
||||
let field_visitor = deserialize_field_identifier(&field_names_idents, cattrs, has_flatten);
|
||||
|
||||
// untagged struct variants do not get a visit_seq method. The same applies to
|
||||
@ -1838,7 +1837,6 @@ fn deserialize_externally_tagged_variant(
|
||||
params,
|
||||
&variant.fields,
|
||||
cattrs,
|
||||
variant.attrs.has_flatten(),
|
||||
StructForm::ExternallyTagged(variant_ident),
|
||||
),
|
||||
}
|
||||
@ -1882,7 +1880,6 @@ fn deserialize_internally_tagged_variant(
|
||||
params,
|
||||
&variant.fields,
|
||||
cattrs,
|
||||
variant.attrs.has_flatten(),
|
||||
StructForm::InternallyTagged(variant_ident, deserializer),
|
||||
),
|
||||
Style::Tuple => unreachable!("checked in serde_derive_internals"),
|
||||
@ -1940,7 +1937,6 @@ fn deserialize_untagged_variant(
|
||||
params,
|
||||
&variant.fields,
|
||||
cattrs,
|
||||
variant.attrs.has_flatten(),
|
||||
StructForm::Untagged(variant_ident, deserializer),
|
||||
),
|
||||
}
|
||||
|
@ -547,6 +547,12 @@ fn test_gen() {
|
||||
}
|
||||
assert::<FlattenWith>();
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Flatten<T> {
|
||||
#[serde(flatten)]
|
||||
t: T,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct FlattenDenyUnknown<T> {
|
||||
@ -554,6 +560,19 @@ fn test_gen() {
|
||||
t: T,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct SkipDeserializing<T> {
|
||||
#[serde(skip_deserializing)]
|
||||
flat: T,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct SkipDeserializingDenyUnknown<T> {
|
||||
#[serde(skip_deserializing)]
|
||||
flat: T,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct StaticStrStruct<'a> {
|
||||
a: &'a str,
|
||||
@ -720,14 +739,11 @@ fn test_gen() {
|
||||
flat: StdOption<T>,
|
||||
}
|
||||
|
||||
#[allow(clippy::collection_is_never_read)] // FIXME
|
||||
const _: () = {
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct FlattenSkipDeserializing<T> {
|
||||
#[serde(flatten, skip_deserializing)]
|
||||
flat: T,
|
||||
}
|
||||
};
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct FlattenSkipDeserializing<T> {
|
||||
#[serde(flatten, skip_deserializing)]
|
||||
flat: T,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
|
Loading…
Reference in New Issue
Block a user