Skip to content

Commit

Permalink
fix(serde): Improve spans for empty tables
Browse files Browse the repository at this point in the history
Fixes #669
  • Loading branch information
epage committed Jan 31, 2024
1 parent d5423f6 commit 7e23971
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion crates/toml/tests/testsuite/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1373,5 +1373,5 @@ edition = "2021"
Ok(_) => panic!("should fail"),
Err(err) => err,
};
assert_eq!(err.span(), Some(0..0));
assert_eq!(err.span(), Some(61..66));
}
8 changes: 4 additions & 4 deletions crates/toml_edit/src/de/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl crate::InlineTable {
pub(crate) struct TableMapAccess {
iter: indexmap::map::IntoIter<crate::InternalString, crate::table::TableKeyValue>,
span: Option<std::ops::Range<usize>>,
value: Option<(crate::InternalString, crate::Item)>,
value: Option<(crate::Key, crate::Item)>,
}

impl TableMapAccess {
Expand Down Expand Up @@ -149,7 +149,7 @@ impl<'de> serde::de::MapAccess<'de> for TableMapAccess {
}
e
});
self.value = Some((v.key.into(), v.value));
self.value = Some((v.key, v.value));
ret
}
None => Ok(None),
Expand All @@ -162,13 +162,13 @@ impl<'de> serde::de::MapAccess<'de> for TableMapAccess {
{
match self.value.take() {
Some((k, v)) => {
let span = v.span();
let span = v.span().or_else(|| k.span());
seed.deserialize(crate::de::ValueDeserializer::new(v))
.map_err(|mut e: Self::Error| {
if e.span().is_none() {
e.set_span(span);
}
e.add_key(k.as_str().to_owned());
e.add_key(k.get().to_owned());
e
})
}
Expand Down

0 comments on commit 7e23971

Please sign in to comment.