Enforce unit struct for #[serde(other)]
This commit is contained in:
parent
0156f1355a
commit
dcd2232f69
@ -1866,8 +1866,8 @@ fn deserialize_generated_identifier(
|
||||
let ignore_variant = quote!(__other(_serde::private::de::Content<'de>),);
|
||||
let fallthrough = quote!(_serde::export::Ok(__Field::__other(__value)));
|
||||
(Some(ignore_variant), Some(fallthrough))
|
||||
} else if other_idx.is_some() {
|
||||
let ignore_variant = fields[other_idx.unwrap()].1.clone();
|
||||
} else if let Some(other_idx) = other_idx {
|
||||
let ignore_variant = fields[other_idx].1.clone();
|
||||
let fallthrough = quote!(_serde::export::Ok(__Field::#ignore_variant));
|
||||
(None, Some(fallthrough))
|
||||
} else if is_variant || cattrs.deny_unknown_fields() {
|
||||
|
@ -124,15 +124,14 @@ fn check_identifier(cx: &Ctxt, cont: &Container) {
|
||||
}
|
||||
|
||||
// Variant with `other` attribute must be the last one.
|
||||
(Style::Unit, Identifier::Field, true, _) | (_, Identifier::No, true, _) => {
|
||||
(Style::Unit, Identifier::Field, true, _) | (Style::Unit, Identifier::No, true, _) => {
|
||||
if i < variants.len() - 1 {
|
||||
cx.error("#[serde(other)] must be the last variant");
|
||||
}
|
||||
}
|
||||
|
||||
// Variant with `other` attribute must be a unit variant.
|
||||
// TODO: Only in field_identifier ?
|
||||
(_, Identifier::Field, true, _) => {
|
||||
(_, Identifier::Field, true, _) | (_, Identifier::No, true, _) => {
|
||||
cx.error("#[serde(other)] must be on a unit variant");
|
||||
},
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user