From 7e239714d05121fbd9d111224f7a11a7d9d99134 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 31 Jan 2024 10:26:03 -0600 Subject: [PATCH] fix(serde): Improve spans for empty tables Fixes #669 --- crates/toml/tests/testsuite/serde.rs | 2 +- crates/toml_edit/src/de/table.rs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/toml/tests/testsuite/serde.rs b/crates/toml/tests/testsuite/serde.rs index ab1f98a7..d7f8bc40 100644 --- a/crates/toml/tests/testsuite/serde.rs +++ b/crates/toml/tests/testsuite/serde.rs @@ -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)); } diff --git a/crates/toml_edit/src/de/table.rs b/crates/toml_edit/src/de/table.rs index 0b6183e0..33aa3970 100644 --- a/crates/toml_edit/src/de/table.rs +++ b/crates/toml_edit/src/de/table.rs @@ -118,7 +118,7 @@ impl crate::InlineTable { pub(crate) struct TableMapAccess { iter: indexmap::map::IntoIter, span: Option>, - value: Option<(crate::InternalString, crate::Item)>, + value: Option<(crate::Key, crate::Item)>, } impl TableMapAccess { @@ -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), @@ -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 }) }