Added ui tests, Limited serde(tag = "...") to structs with named field
Added ui test struct-representation/internally-tagged-unit Added ui test struct-representation/internally-tagged-tuple Limited the serde(tag = "...") to enums and structs with named field
This commit is contained in:
parent
9e53405f43
commit
2359417804
@ -358,16 +358,30 @@ impl Container {
|
||||
Meta(NameValue(ref m)) if m.ident == "tag" => {
|
||||
if let Ok(s) = get_lit_str(cx, &m.ident, &m.ident, &m.lit) {
|
||||
match item.data {
|
||||
syn::Data::Enum(_) |
|
||||
syn::Data::Struct(_, ..) => {
|
||||
syn::Data::Enum(_) => {
|
||||
internal_tag.set(&m.ident, s.value());
|
||||
}
|
||||
syn::Data::Struct(syn::DataStruct{ref fields, ..}) => {
|
||||
match *fields {
|
||||
syn::Fields::Named(_) => {
|
||||
internal_tag.set(&m.ident, s.value());
|
||||
},
|
||||
syn::Fields::Unnamed(_) | syn::Fields::Unit => {
|
||||
cx.error_spanned_by(
|
||||
fields,
|
||||
"#[serde(tag = \"...\")] can only be used on enums \
|
||||
and structs with named fields",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
syn::Data::Union(syn::DataUnion {
|
||||
ref union_token, ..
|
||||
}) => {
|
||||
cx.error_spanned_by(
|
||||
union_token,
|
||||
"#[serde(tag = \"...\")] can only be used on enums",
|
||||
"#[serde(tag = \"...\")] can only be used on enums \
|
||||
and structs with named fields",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1411,7 +1411,6 @@ fn test_internally_tagged_struct() {
|
||||
Token::StructEnd,
|
||||
],
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -0,0 +1,11 @@
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[serde(tag = "type")]
|
||||
struct S (
|
||||
u8,
|
||||
u8
|
||||
);
|
||||
|
||||
fn main() {}
|
@ -0,0 +1,12 @@
|
||||
error: #[serde(tag = "...")] can only be used on enums and structs with named fields
|
||||
--> $DIR/internally-taged-tuple.rs:6:10
|
||||
|
|
||||
6 | struct S (
|
||||
| __________^
|
||||
7 | | u8,
|
||||
8 | | u8
|
||||
9 | | );
|
||||
| |_^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
@ -0,0 +1,8 @@
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[serde(tag = "type")]
|
||||
struct U;
|
||||
|
||||
fn main() {}
|
@ -0,0 +1,8 @@
|
||||
error: #[serde(tag = "...")] can only be used on enums and structs with named fields
|
||||
--> $DIR/internally-tagged-unit.rs:4:10
|
||||
|
|
||||
4 | #[derive(Serialize)]
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
Loading…
x
Reference in New Issue
Block a user