Skip to content

Commit bb96b3a

Browse files
committed
Auto merge of #10086 - epage:toml, r=ehuss
Port cargo from toml-rs to toml_edit Benefits: - A TOML 1.0 compliant parser - Unblock future work - Have `cargo init` add the current crate to the workspace, rather than error - #5586: Upstream `cargo-add` TODO - [x] Analyze performance and address regressions - [x] Identify and resolve incompatibiies - [x] Resolve remaining test failures, see https://github.com/ordian/toml_edit/labels/cargo - [x] ~~Switch the code from #10176 to only parse once~~ (this PR is being merged first)
2 parents 7e89966 + 320c279 commit bb96b3a

34 files changed

+176
-38
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ strip-ansi-escapes = "0.1.0"
5757
tar = { version = "0.4.36", default-features = false }
5858
tempfile = "3.0"
5959
termcolor = "1.1"
60-
toml = "0.5.7"
60+
toml_edit = { version = "0.13", features = ["serde", "easy"] }
6161
unicode-xid = "0.2.0"
6262
url = "2.2.2"
6363
walkdir = "2.2"

benches/capture/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ description = "Tool for capturing a real-world workspace for benchmarking."
99
cargo_metadata = "0.14.0"
1010
flate2 = { version = "1.0.3", default-features = false, features = ["zlib"] }
1111
tar = { version = "0.4.35", default-features = false }
12-
toml = "0.5.8"
12+
toml_edit = { version = "0.9.1", features = ["easy"] }

benches/capture/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use flate2::{Compression, GzBuilder};
88
use std::fs;
99
use std::path::{Path, PathBuf};
1010
use std::process::Command;
11+
use toml_edit::easy as toml;
1112

1213
fn main() {
1314
let force = std::env::args().any(|arg| arg == "-f");

crates/cargo-test-support/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ remove_dir_all = "0.5"
2121
serde_json = "1.0"
2222
tar = { version = "0.4.18", default-features = false }
2323
termcolor = "1.1.2"
24-
toml = "0.5.7"
24+
toml_edit = { version = "0.9.1", features = ["serde", "easy"] }
2525
url = "2.2.2"
2626

2727
[features]

crates/cargo-test-support/src/registry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ impl Package {
709709
if !self.cargo_features.is_empty() {
710710
manifest.push_str(&format!(
711711
"cargo-features = {}\n\n",
712-
toml::to_string(&self.cargo_features).unwrap()
712+
toml_edit::ser::to_item(&self.cargo_features).unwrap()
713713
));
714714
}
715715

src/cargo/core/manifest.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use anyhow::Context as _;
99
use semver::Version;
1010
use serde::ser;
1111
use serde::Serialize;
12+
use toml_edit::easy as toml;
1213
use url::Url;
1314

1415
use crate::core::compiler::{CompileKind, CrateType};

src/cargo/core/package.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use lazycell::LazyCell;
1616
use log::{debug, warn};
1717
use semver::Version;
1818
use serde::Serialize;
19+
use toml_edit::easy as toml;
1920

2021
use crate::core::compiler::{CompileKind, RustcTargetData};
2122
use crate::core::dependency::DepKind;
@@ -199,7 +200,7 @@ impl Package {
199200
.manifest()
200201
.original()
201202
.prepare_for_publish(ws, self.root())?;
202-
let toml = toml::to_string(&manifest)?;
203+
let toml = toml::to_string_pretty(&manifest)?;
203204
Ok(format!("{}\n{}", MANIFEST_PREAMBLE, toml))
204205
}
205206

src/cargo/core/workspace.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use anyhow::{bail, Context as _};
88
use glob::glob;
99
use itertools::Itertools;
1010
use log::debug;
11+
use toml_edit::easy as toml;
1112
use url::Url;
1213

1314
use crate::core::features::Features;

src/cargo/ops/cargo_config.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,19 +127,24 @@ fn print_toml(config: &Config, opts: &GetOptions<'_>, key: &ConfigKey, cv: &CV)
127127
config,
128128
"{} = {}{}",
129129
key,
130-
toml::to_string(&val).unwrap(),
130+
toml_edit::Value::from(val),
131131
origin(def)
132132
),
133133
CV::List(vals, _def) => {
134134
if opts.show_origin {
135135
drop_println!(config, "{} = [", key);
136136
for (val, def) in vals {
137-
drop_println!(config, " {}, # {}", toml::to_string(&val).unwrap(), def);
137+
drop_println!(
138+
config,
139+
" {}, # {}",
140+
toml_edit::ser::to_item(&val).unwrap(),
141+
def
142+
);
138143
}
139144
drop_println!(config, "]");
140145
} else {
141-
let vals: Vec<&String> = vals.iter().map(|x| &x.0).collect();
142-
drop_println!(config, "{} = {}", key, toml::to_string(&vals).unwrap());
146+
let vals: toml_edit::Array = vals.iter().map(|x| &x.0).collect();
147+
drop_println!(config, "{} = {}", key, vals);
143148
}
144149
}
145150
CV::Table(table, _def) => {

src/cargo/ops/cargo_new.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use std::io::{BufRead, BufReader, ErrorKind};
1212
use std::path::{Path, PathBuf};
1313
use std::process::Command;
1414
use std::str::{from_utf8, FromStr};
15+
use toml_edit::easy as toml;
1516

1617
#[derive(Clone, Copy, Debug, PartialEq)]
1718
pub enum VersionControl {

0 commit comments

Comments
 (0)