Allow flatten attribute in enums
This commit is contained in:
parent
5098609935
commit
978d64993e
@ -6,7 +6,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use internals::ast::{Container, Data, Style};
|
||||
use internals::ast::{Container, Data, Field, Style};
|
||||
use internals::attr::{EnumTag, Identifier};
|
||||
use internals::Ctxt;
|
||||
|
||||
@ -44,15 +44,24 @@ fn check_getter(cx: &Ctxt, cont: &Container) {
|
||||
/// Flattening has some restrictions we can test.
|
||||
fn check_flatten(cx: &Ctxt, cont: &Container) {
|
||||
match cont.data {
|
||||
Data::Enum(_) => {
|
||||
if cont.attrs.has_flatten() {
|
||||
cx.error("#[serde(flatten)] cannot be used within enums");
|
||||
Data::Enum(ref variants) => {
|
||||
for variant in variants {
|
||||
for field in &variant.fields {
|
||||
check_flatten_field(cx, variant.style, field);
|
||||
}
|
||||
}
|
||||
Data::Struct(style, _) => {
|
||||
for field in cont.data.all_fields() {
|
||||
}
|
||||
Data::Struct(style, ref fields) => {
|
||||
for field in fields {
|
||||
check_flatten_field(cx, style, field);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn check_flatten_field(cx: &Ctxt, style: Style, field: &Field) {
|
||||
if !field.attrs.flatten() {
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
match style {
|
||||
Style::Tuple => {
|
||||
@ -79,9 +88,6 @@ fn check_flatten(cx: &Ctxt, cont: &Container) {
|
||||
#[serde(skip_deserializing)]",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The `other` attribute must be used at most once and it must be the last
|
||||
|
Loading…
x
Reference in New Issue
Block a user