Repository: toml-rs/toml (rust)

Issue:
Incorrect roundtripping when table sources are mixed
```toml
[package]
metadata.msrv = "1.65.0"

[[package.metadata.release.pre-release-replacements]]
```

When loading and then writing the above, the array of tables if lost

From crate-ci/cargo-release#653

Pull request description:
fix(edit): Ensure std tables under dotted tables are printed
Fixes #527

Patch:
diff --git a/crates/toml_edit/src/encode.rs b/crates/toml_edit/src/encode.rs
index 4747bd52..ea24c2db 100644
--- a/crates/toml_edit/src/encode.rs
+++ b/crates/toml_edit/src/encode.rs
@@ -237,11 +237,13 @@ fn visit_nested_tables<'t, F>(
 where
     F: FnMut(&'t Table, &Vec<&'t Key>, bool) -> Result,
 {
-    callback(table, path, is_array_of_tables)?;
+    if !table.is_dotted() {
+        callback(table, path, is_array_of_tables)?;
+    }
 
     for kv in table.items.values() {
         match kv.value {
-            Item::Table(ref t) if !t.is_dotted() => {
+            Item::Table(ref t) => {
                 path.push(&kv.key);
                 visit_nested_tables(t, path, false, callback)?;
                 path.pop();


Test patch:
diff --git a/crates/toml_edit/tests/testsuite/parse.rs b/crates/toml_edit/tests/testsuite/parse.rs
index ed3ca303..4155e97e 100644
--- a/crates/toml_edit/tests/testsuite/parse.rs
+++ b/crates/toml_edit/tests/testsuite/parse.rs
@@ -231,6 +231,19 @@ fn empty_table() {
     table["foo"].as_table().unwrap();
 }
 
+#[test]
+fn mixed_table_issue_527() {
+    let input = r#"
+[package]
+metadata.msrv = "1.65.0"
+
+[package.metadata.release.pre-release-replacements]
+"#;
+    let document = input.parse::<Document>().unwrap();
+    let actual = document.to_string();
+    assert_eq(input, actual);
+}
+
 #[test]
 fn fruit() {
     let table = r#"