-
Notifications
You must be signed in to change notification settings - Fork 115
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
Missing spans for errors in variant fields #535
Comments
I'm not seeing how we could support this.
See also #589 |
True; for what it's worth, in my concrete use case the tag is always the first field, so using a custom deserializer works pretty well - adjusted for the example above, it would say: impl<'de> Deserialize<'de> for Foo {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
struct FooVisitor;
impl<'de> de::Visitor<'de> for FooVisitor {
type Value = Foo;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
write!(formatter, "a Foo")
}
fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error>
where
A: de::MapAccess<'de>,
{
let tag_key = map.next_key::<String>()?;
assert_eq!("type", tag_key.unwrap());
let tag_value = map.next_value::<String>()?;
match tag_value.as_str() {
"Bar" => Ok(Foo::Bar(Deserialize::deserialize(
de::value::MapAccessDeserializer::new(map),
)?)),
tag => Err(A::Error::custom(format!("unknown tag: {tag}"))),
}
}
}
deserializer.deserialize_map(FooVisitor)
}
} |
Hi,
Following test fails:
... saying:
(ofc. changing
Spanned<String>
to justString
works.)I think the underlying reason is that using an enum (at least in the way presented above) gets expanded by Serde into a call to
deserialize_any()
, which later makes this boi:toml/crates/toml_edit/src/de/value.rs
Line 55 in 9e43da1
... unaware of the "spanned" context it's being invoked on 😢
See also
flatten
#589 forflatten
The text was updated successfully, but these errors were encountered: