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

Incorrect line/column info when using tag setting with nested enums #870

Open
mkovaxx opened this issue Mar 18, 2022 · 1 comment
Open

Comments

@mkovaxx
Copy link

mkovaxx commented Mar 18, 2022

Project for easy repro here.

Code:

const JSON_TEXT: &str = r#"
{
    "things_tag": "animals",
    "items": [
        {"animal_tag": "cat"},
        {"animal_tag": "xenomorph"},
        {"animal_tag": "dog"}
    ]
}
"#;

fn main() {
    let stuff = serde_json::from_str::<Things>(JSON_TEXT);
    println!("{:?}", stuff);
}

#[derive(Debug, serde::Serialize, serde::Deserialize)]
#[serde(tag = "things_tag", rename_all = "snake_case")]
enum Things {
    Animals(Animals),
    Plants(Plants),
}

#[derive(Debug, serde::Serialize, serde::Deserialize)]
struct Animals {
    items: Vec<Animal>,
}

#[derive(Debug, serde::Serialize, serde::Deserialize)]
#[serde(tag = "animal_tag", rename_all = "snake_case")]
enum Animal {
    Cat,
    Dog,
}

#[derive(Debug, serde::Serialize, serde::Deserialize)]
struct Plants {}

Expected output:

Err(Error("unknown variant `xenomorph`, expected `cat` or `dog`", line: 6, column: 34))

Observed output:

Err(Error("unknown variant `xenomorph`, expected `cat` or `dog`", line: 0, column: 0))

Note how the line: 0, column: 0 information is incorrect.

The problem disappears when the tag = "things_tag" setting is removed (branch), but persists when only the tag = "animal_tag" is removed (branch).

@mkovaxx
Copy link
Author

mkovaxx commented Mar 21, 2022

Seems related to serde-rs/serde#1621

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant