Skip to content

Replacing an InlineTable with a comment with a Table results in invalid syntax #691

Open
@nrabulinski

Description

@nrabulinski
use std::str::FromStr;

use toml_edit::{Document, Item, Table};

fn main() {
    let mut val = Document::from_str(
        r#"
    # hello i'm a comment
    foo = { bar = 1 }
    "#,
    )
    .unwrap();
    println!("before: {}", val.to_string());
    let mut new_foo = Table::new();
    new_foo.insert("bar", Item::Value(1.into()));
    new_foo.insert("baz", Item::Value(2.into()));
    *val.get_mut("foo").unwrap() = Item::Table(new_foo);
    println!("after: {}", val.to_string());
}

Expected output:

before:
    # hello i'm a comment
    foo = { bar = 1 }

after:
    # hello i'm a comment
    [foo]
    bar = 1
    baz = 2

Actual output:

before:
    # hello i'm a comment
    foo = { bar = 1 }

after: [
    # hello i'm a comment
    foo ]
bar = 1
baz = 2

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-editArea: TOML editing APIC-bugCategory: Things not working as expectedM-breaking-changeMeta: Implementing or merging this will introduce a breaking change.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions