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

Bad span with untagged enum #748

Closed
nilehmann opened this issue Jul 7, 2024 · 1 comment
Closed

Bad span with untagged enum #748

nilehmann opened this issue Jul 7, 2024 · 1 comment

Comments

@nilehmann
Copy link

I'm getting the wrong spans with the following (playground)

use toml;
use serde::Deserialize;

#[derive(Deserialize)]
struct S {
    key: Vec<E>,
}

#[derive(Deserialize)]
#[serde(untagged)]
enum E {
    A { a: String },
    B { b: String },
}

fn main() {
    let s = r#"
[[key]]
a = "good"
    
[[key]]
c = "bad"
"#;
    if let Err(err) = toml::from_str::<S>(s) {
        println!("{err}")
    }
}
TOML parse error at line 2, column 1
  |
2 | [[key]]
  | ^^^^^^^
data did not match any variant of untagged enum E

I'd expect the error to be in line 5. I'm unsure if it's related to the untagged enum, but I've tried other variations without the untagged enum and it seems to work.

@epage
Copy link
Member

epage commented Jul 7, 2024

This is an issue within serde_derive, see #535. While the original post is focused on internally-tagged enums, it applies to that as well as untagged enums. Closing in favor of that issue. If there is a reason we should keep this open separately, let us know!

@epage epage closed this as not planned Won't fix, can't repro, duplicate, stale Jul 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants