Skip to content

Comments between lines in a table are duplicated #673

@kpreid

Description

@kpreid

Repro that just round-trips some toml:

[dependencies]
pretty_assertions = "=1.3.0"
toml_edit = "=0.21.1"
#[test]
fn toml_edit_bug() {
    use pretty_assertions::assert_eq;

    let text = r###"
[workspace.lints]
rust.unsafe_op_in_unsafe_fn = "deny"

rust.explicit_outlives_requirements = "warn"
# rust.unused_crate_dependencies = "warn"

clippy.cast_lossless = "warn"
clippy.doc_markdown = "warn"
clippy.exhaustive_enums = "warn"
"###;

    let manifest: toml_edit::Document = text.parse().unwrap();

    assert_eq!(text, manifest.to_string());
}

The text should be identical, but it is not. Specifically, the whitespace between the first two items is deleted, and the comment and whitespace are duplicated between all following pairs of items.

 [workspace.lints]
 rust.unsafe_op_in_unsafe_fn = "deny"
-
 rust.explicit_outlives_requirements = "warn"
 # rust.unused_crate_dependencies = "warn"
 
 clippy.cast_lossless = "warn"
+# rust.unused_crate_dependencies = "warn"
+
 clippy.doc_markdown = "warn"
+# rust.unused_crate_dependencies = "warn"
+
 clippy.exhaustive_enums = "warn"

The same behavior happens with toml_edit 0.19.15, so this is not a new bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-outputArea: Outputting TOMLC-bugCategory: Things not working as expected

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions