Merge pull request #1205 from mitsuhiko/bugfix/tuple-struct-flatten
Produce error message for use of flatten in tuple structs
This commit is contained in:
commit
860241aa88
@ -49,11 +49,20 @@ fn check_flatten(cx: &Ctxt, cont: &Container) {
|
|||||||
cx.error("#[serde(flatten)] cannot be used within enums");
|
cx.error("#[serde(flatten)] cannot be used within enums");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Data::Struct(_, _) => {
|
Data::Struct(style, _) => {
|
||||||
for field in cont.data.all_fields() {
|
for field in cont.data.all_fields() {
|
||||||
if !field.attrs.flatten() {
|
if !field.attrs.flatten() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
match style {
|
||||||
|
Style::Tuple => {
|
||||||
|
cx.error("#[serde(flatten)] cannot be used on tuple structs");
|
||||||
|
}
|
||||||
|
Style::Newtype => {
|
||||||
|
cx.error("#[serde(flatten)] cannot be used on newtype structs");
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
if field.attrs.skip_serializing() {
|
if field.attrs.skip_serializing() {
|
||||||
cx.error(
|
cx.error(
|
||||||
"#[serde(flatten] can not be combined with \
|
"#[serde(flatten] can not be combined with \
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
// Copyright 2018 Serde Developers
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate serde_derive;
|
||||||
|
|
||||||
|
#[derive(Serialize)] //~ ERROR: proc-macro derive panicked
|
||||||
|
//~^ HELP: #[serde(flatten)] cannot be used on newtype structs
|
||||||
|
struct Foo(#[serde(flatten)] HashMap<String, String>);
|
||||||
|
|
||||||
|
fn main() {}
|
@ -0,0 +1,16 @@
|
|||||||
|
// Copyright 2018 Serde Developers
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate serde_derive;
|
||||||
|
|
||||||
|
#[derive(Serialize)] //~ ERROR: proc-macro derive panicked
|
||||||
|
//~^ HELP: #[serde(flatten)] cannot be used on tuple structs
|
||||||
|
struct Foo(u32, #[serde(flatten)] HashMap<String, String>);
|
||||||
|
|
||||||
|
fn main() {}
|
Loading…
Reference in New Issue
Block a user