Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#[serde(default)] is ignored in newtype structs, newtype variants, tuple structs and tuple variants #1418

Closed
hcpl opened this issue Nov 2, 2018 · 1 comment
Labels

Comments

@hcpl
Copy link
Contributor

hcpl commented Nov 2, 2018

#[derive(Deserialize)]
struct Foo;

#[derive(Deserialize)]
// should error with "the trait `std::default::Default` is not implemented for `Foo`"
struct Boom(#[serde(default)] Foo);

#[derive(Deserialize)]
// should error with "the trait `std::default::Default` is not implemented for `Foo`"
struct Bar(#[serde(default)] Foo, Foo);

#[derive(Deserialize)]
enum Badum {
    // should error with "the trait `std::default::Default` is not implemented for `Foo`"
    Tss(#[serde(default)] Foo),
}

#[derive(Deserialize)]
enum Baz {
    // should error with "the trait `std::default::Default` is not implemented for `Foo`"
    Spam(#[serde(default)] Foo, Foo),
}

EDIT: also ignored in newtype structs and newtype variants.

Playground.

@hcpl hcpl changed the title #[serde(default)] is ignored in tuple structs and tuple variants #[serde(default)] is ignored in newtype structs, newtype variants, tuple structs and tuple variants Nov 2, 2018
@dtolnay dtolnay added the derive label Feb 2, 2019
@Mingun
Copy link
Contributor

Mingun commented May 28, 2023

Currently only

#[derive(Deserialize)]
enum Badum {
    // should error with "the trait `std::default::Default` is not implemented for `Foo`"
    Tss(#[serde(default)] Foo),
}

case doesn't produce an error, because of #2105, so this issue can be closed as duplicate of #2105.

@oli-obk oli-obk closed this as completed May 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

4 participants