Skip to content

Commit 5a23b1e

Browse files
committed
fix(edit): Correctly deserialize Spanned implicit tables
Fixes #798
1 parent 4ab7552 commit 5a23b1e

File tree

3 files changed

+66
-11
lines changed

3 files changed

+66
-11
lines changed

crates/toml_edit/src/parser/document.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ fn descend_path<'t>(
458458
table = match table.entry_format(key) {
459459
crate::Entry::Vacant(entry) => {
460460
let mut new_table = Table::new();
461+
new_table.span = key.span();
461462
new_table.set_implicit(true);
462463
new_table.set_dotted(dotted);
463464

crates/toml_edit/src/parser/inline_table.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ fn descend_path<'a>(
232232
table = match table.entry_format(key) {
233233
crate::InlineEntry::Vacant(entry) => {
234234
let mut new_table = InlineTable::new();
235+
new_table.span = key.span();
235236
new_table.set_implicit(true);
236237
new_table.set_dotted(dotted);
237238
entry

crates/toml_edit/tests/serde/spanned.rs

Lines changed: 64 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -343,18 +343,71 @@ alice.bob = { one.two = "qux" }
343343

344344
let result = crate::from_str::<SpannedValue>(INPUT);
345345
assert_data_eq!(
346-
result.unwrap_err().to_string(),
346+
result.unwrap().to_debug(),
347347
str![[r#"
348-
TOML parse error at line 1, column 1
349-
|
350-
1 |
351-
| ^
352-
invalid type: string "bar", expected a borrowed string
353-
354-
355-
356-
in `foo`
357-
348+
Map(
349+
[
350+
(
351+
"foo",
352+
Spanned {
353+
span: 2..5,
354+
value: Map(
355+
[
356+
(
357+
"bar",
358+
Spanned {
359+
span: 1..10,
360+
value: Map(
361+
[
362+
(
363+
"alice",
364+
Spanned {
365+
span: 11..16,
366+
value: Map(
367+
[
368+
(
369+
"bob",
370+
Spanned {
371+
span: 23..42,
372+
value: Map(
373+
[
374+
(
375+
"one",
376+
Spanned {
377+
span: 25..28,
378+
value: Map(
379+
[
380+
(
381+
"two",
382+
Spanned {
383+
span: 35..40,
384+
value: String(
385+
"qux",
386+
),
387+
},
388+
),
389+
],
390+
),
391+
},
392+
),
393+
],
394+
),
395+
},
396+
),
397+
],
398+
),
399+
},
400+
),
401+
],
402+
),
403+
},
404+
),
405+
],
406+
),
407+
},
408+
),
409+
],
410+
)
358411
359412
"#]]
360413
);

0 commit comments

Comments
 (0)