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 panics when flattening struct and Value #1379

Closed
chrisduerr opened this issue Sep 8, 2018 · 1 comment
Closed

Serde panics when flattening struct and Value #1379

chrisduerr opened this issue Sep 8, 2018 · 1 comment
Labels

Comments

@chrisduerr
Copy link

When trying to deserialize a struct which contains another struct with the #[serde(flatten)] annotation and a field with the #[serde(flatten)] annotation and the type toml::Value (same with serde_yaml or serde_json), serde will panic.

A minimal example for reproducing this:

extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate toml;

#[derive(Debug, Deserialize)]
struct Test {
    text: Option<String>,
    #[serde(flatten)]
    settings: Settings,
    #[serde(flatten)]
    extra: toml::Value,
}

#[derive(Debug, Deserialize)]
struct Settings {
    width: Option<u8>,
}

fn main() {
    let file = "text = \"test\"\nwidth = 8";
    let test: Test = toml::from_str(file).unwrap();
}

playground

This will result in the following error:

thread 'main' panicked at 'called `Option::unwrap()` on a `None` value'
@dtolnay
Copy link
Member

dtolnay commented Sep 9, 2018

Fixed in serde 1.0.78.

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

2 participants