Skip to content

Commit 326b841

Browse files
committed
chore: Update to toml v0.6, toml_edit v0.18
`toml` replaces `toml_edit::easy`, using `toml_edit` as its parser.
1 parent d73b935 commit 326b841

32 files changed

+147
-180
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ tar = { version = "0.4.38", default-features = false }
6464
tempfile = "3.0"
6565
termcolor = "1.1"
6666
time = { version = "0.3", features = ["parsing", "formatting"]}
67-
toml_edit = { version = "0.15.0", features = ["serde", "easy", "perf"] }
67+
toml_edit = "0.18.0"
68+
toml = "0.6.0"
6869
unicode-xid = "0.2.0"
6970
url = "2.2.2"
7071
walkdir = "2.2"

benches/capture/src/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ 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;
1211

1312
fn main() {
1413
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
@@ -25,7 +25,7 @@ serde = { version = "1.0.123", features = ["derive"] }
2525
serde_json = "1.0"
2626
tar = { version = "0.4.38", default-features = false }
2727
termcolor = "1.1.2"
28-
toml_edit = { version = "0.15.0", features = ["serde", "easy", "perf"] }
28+
toml = "0.6.0"
2929
url = "2.2.2"
3030

3131
[target.'cfg(windows)'.dependencies]

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,10 +1391,13 @@ impl Package {
13911391
let mut manifest = String::new();
13921392

13931393
if !self.cargo_features.is_empty() {
1394-
manifest.push_str(&format!(
1395-
"cargo-features = {}\n\n",
1396-
toml_edit::ser::to_item(&self.cargo_features).unwrap()
1397-
));
1394+
let mut features = String::new();
1395+
serde::Serialize::serialize(
1396+
&self.cargo_features,
1397+
toml::ser::ValueSerializer::new(&mut features),
1398+
)
1399+
.unwrap();
1400+
manifest.push_str(&format!("cargo-features = {}\n\n", features));
13981401
}
13991402

14001403
manifest.push_str(&format!(

src/cargo/core/manifest.rs

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

1514
use crate::core::compiler::rustdoc::RustdocScrapeExamples;

src/cargo/core/package.rs

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

2120
use crate::core::compiler::{CompileKind, RustcTargetData};
2221
use crate::core::dependency::DepKind;

src/cargo/core/workspace.rs

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

1413
use crate::core::compiler::Unit;

src/cargo/ops/cargo_config.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ fn print_toml(config: &Config, opts: &GetOptions<'_>, key: &ConfigKey, cv: &CV)
137137
drop_println!(
138138
config,
139139
" {}, # {}",
140-
toml_edit::ser::to_item(&val).unwrap(),
140+
serde::Serialize::serialize(val, toml_edit::ser::ValueSerializer::new())
141+
.unwrap(),
141142
def
142143
);
143144
}

src/cargo/ops/cargo_new.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use std::io::{BufRead, BufReader, ErrorKind};
1212
use std::path::{Path, PathBuf};
1313
use std::str::FromStr;
1414
use std::{fmt, slice};
15-
use toml_edit::easy as toml;
1615

1716
#[derive(Clone, Copy, Debug, PartialEq)]
1817
pub enum VersionControl {

src/cargo/ops/cargo_output_metadata.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use cargo_platform::Platform;
1111
use serde::Serialize;
1212
use std::collections::BTreeMap;
1313
use std::path::PathBuf;
14-
use toml_edit::easy as toml;
1514

1615
const VERSION: u32 = 1;
1716

src/cargo/ops/common_for_install_and_uninstall.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use std::task::Poll;
99
use anyhow::{bail, format_err, Context as _};
1010
use ops::FilterRule;
1111
use serde::{Deserialize, Serialize};
12-
use toml_edit::easy as toml;
1312

1413
use crate::core::compiler::{DirtyReason, Freshness};
1514
use crate::core::Target;

src/cargo/ops/lockfile.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::util::toml as cargo_toml;
66
use crate::util::Filesystem;
77

88
use anyhow::Context as _;
9-
use toml_edit::easy as toml;
109

1110
pub fn load_pkg_lockfile(ws: &Workspace<'_>) -> CargoResult<Option<Resolve>> {
1211
if !ws.root().join("Cargo.lock").exists() {
@@ -21,7 +20,7 @@ pub fn load_pkg_lockfile(ws: &Workspace<'_>) -> CargoResult<Option<Resolve>> {
2120
.with_context(|| format!("failed to read file: {}", f.path().display()))?;
2221

2322
let resolve = (|| -> CargoResult<Option<Resolve>> {
24-
let resolve: toml::Value = cargo_toml::parse(&s, f.path(), ws.config())?;
23+
let resolve: toml::Table = cargo_toml::parse_document(&s, f.path(), ws.config())?;
2524
let v: resolver::EncodableResolve = resolve.try_into()?;
2625
Ok(Some(v.into_resolve(&s, ws)?))
2726
})()
@@ -101,7 +100,7 @@ fn resolve_to_string_orig(
101100
}
102101

103102
fn serialize_resolve(resolve: &Resolve, orig: Option<&str>) -> String {
104-
let toml = toml_edit::ser::to_item(resolve).unwrap();
103+
let toml = toml::Table::try_from(resolve).unwrap();
105104

106105
let mut out = String::new();
107106

@@ -140,7 +139,7 @@ fn serialize_resolve(resolve: &Resolve, orig: Option<&str>) -> String {
140139

141140
let deps = toml["package"].as_array().unwrap();
142141
for dep in deps {
143-
let dep = dep.as_inline_table().unwrap();
142+
let dep = dep.as_table().unwrap();
144143

145144
out.push_str("[[package]]\n");
146145
emit_package(dep, &mut out);
@@ -150,7 +149,7 @@ fn serialize_resolve(resolve: &Resolve, orig: Option<&str>) -> String {
150149
let list = patch["unused"].as_array().unwrap();
151150
for entry in list {
152151
out.push_str("[[patch.unused]]\n");
153-
emit_package(entry.as_inline_table().unwrap(), &mut out);
152+
emit_package(entry.as_table().unwrap(), &mut out);
154153
out.push('\n');
155154
}
156155
}
@@ -160,11 +159,11 @@ fn serialize_resolve(resolve: &Resolve, orig: Option<&str>) -> String {
160159
// (which `toml_edit::Table::to_string` only shows)
161160
// 2. We need to ensure all children tables have `metadata.` prefix
162161
let meta_table = meta
163-
.clone()
164-
.into_table()
165-
.expect("validation ensures this is a table");
166-
let mut meta_doc = toml_edit::Document::new();
167-
meta_doc["metadata"] = toml_edit::Item::Table(meta_table);
162+
.as_table()
163+
.expect("validation ensures this is a table")
164+
.clone();
165+
let mut meta_doc = toml::Table::new();
166+
meta_doc.insert("metadata".to_owned(), toml::Value::Table(meta_table));
168167

169168
out.push_str(&meta_doc.to_string());
170169
}
@@ -200,7 +199,7 @@ fn are_equal_lockfiles(orig: &str, current: &str, ws: &Workspace<'_>) -> bool {
200199
orig.lines().eq(current.lines())
201200
}
202201

203-
fn emit_package(dep: &toml_edit::InlineTable, out: &mut String) {
202+
fn emit_package(dep: &toml::Table, out: &mut String) {
204203
out.push_str(&format!("name = {}\n", &dep["name"]));
205204
out.push_str(&format!("version = {}\n", &dep["version"]));
206205

src/cargo/ops/vendor.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use std::ffi::OsStr;
1414
use std::fs::{self, File, OpenOptions};
1515
use std::io::{Read, Write};
1616
use std::path::{Path, PathBuf};
17-
use toml_edit::easy as toml;
1817

1918
pub struct VendorOptions<'a> {
2019
pub no_delete: bool,

src/cargo/util/config/key.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,6 @@ fn escape_key_part<'a>(part: &'a str) -> Cow<'a, str> {
111111
Cow::Borrowed(part)
112112
} else {
113113
// This is a bit messy, but toml doesn't expose a function to do this.
114-
Cow::Owned(toml_edit::Value::from(part).to_string())
114+
Cow::Owned(toml::Value::from(part).to_string())
115115
}
116116
}

src/cargo/util/config/mod.rs

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ use anyhow::{anyhow, bail, format_err, Context as _};
7979
use cargo_util::paths;
8080
use curl::easy::Easy;
8181
use lazycell::LazyCell;
82+
use serde::de::IntoDeserializer as _;
8283
use serde::Deserialize;
83-
use toml_edit::{easy as toml, Item};
84+
use toml_edit::Item;
8485
use url::Url;
8586

8687
mod de;
@@ -903,17 +904,11 @@ impl Config {
903904
let def = Definition::Environment(key.as_env_key().to_string());
904905
if self.cli_unstable().advanced_env && env_val.starts_with('[') && env_val.ends_with(']') {
905906
// Parse an environment string as a TOML array.
906-
let toml_s = format!("value={}", env_val);
907-
let toml_v: toml::Value = toml::de::from_str(&toml_s).map_err(|e| {
908-
ConfigError::new(format!("could not parse TOML list: {}", e), def.clone())
909-
})?;
910-
let values = toml_v
911-
.as_table()
912-
.unwrap()
913-
.get("value")
914-
.unwrap()
915-
.as_array()
916-
.expect("env var was not array");
907+
let toml_v = toml::Value::deserialize(toml::de::ValueDeserializer::new(&env_val))
908+
.map_err(|e| {
909+
ConfigError::new(format!("could not parse TOML list: {}", e), def.clone())
910+
})?;
911+
let values = toml_v.as_array().expect("env var was not array");
917912
for value in values {
918913
// TODO: support other types.
919914
let s = value.as_str().ok_or_else(|| {
@@ -1188,14 +1183,14 @@ impl Config {
11881183
}
11891184
let contents = fs::read_to_string(path)
11901185
.with_context(|| format!("failed to read configuration file `{}`", path.display()))?;
1191-
let toml = cargo_toml::parse(&contents, path, self).with_context(|| {
1186+
let toml = cargo_toml::parse_document(&contents, path, self).with_context(|| {
11921187
format!("could not parse TOML configuration in `{}`", path.display())
11931188
})?;
11941189
let def = match why_load {
11951190
WhyLoad::Cli => Definition::Cli(Some(path.into())),
11961191
WhyLoad::FileDiscovery => Definition::Path(path.into()),
11971192
};
1198-
let value = CV::from_toml(def, toml).with_context(|| {
1193+
let value = CV::from_toml(def, toml::Value::Table(toml)).with_context(|| {
11991194
format!(
12001195
"failed to load TOML configuration from `{}`",
12011196
path.display()
@@ -1310,8 +1305,10 @@ impl Config {
13101305
format!("failed to parse value from --config argument `{arg}` as a dotted key expression")
13111306
})?;
13121307
fn non_empty_decor(d: &toml_edit::Decor) -> bool {
1313-
d.prefix().map_or(false, |p| !p.trim().is_empty())
1314-
|| d.suffix().map_or(false, |s| !s.trim().is_empty())
1308+
d.prefix()
1309+
.map_or(false, |p| !p.as_str().unwrap_or_default().trim().is_empty())
1310+
|| d.suffix()
1311+
.map_or(false, |s| !s.as_str().unwrap_or_default().trim().is_empty())
13151312
}
13161313
let ok = {
13171314
let mut got_to_value = false;
@@ -1371,9 +1368,10 @@ impl Config {
13711368
);
13721369
}
13731370

1374-
let toml_v: toml::Value = toml::from_document(doc).with_context(|| {
1375-
format!("failed to parse value from --config argument `{arg}`")
1376-
})?;
1371+
let toml_v: toml::Value = toml::Value::deserialize(doc.into_deserializer())
1372+
.with_context(|| {
1373+
format!("failed to parse value from --config argument `{arg}`")
1374+
})?;
13771375

13781376
if toml_v
13791377
.get("registry")
@@ -2172,14 +2170,12 @@ pub fn save_credentials(
21722170
)
21732171
})?;
21742172

2175-
let mut toml = cargo_toml::parse(&contents, file.path(), cfg)?;
2173+
let mut toml = cargo_toml::parse_document(&contents, file.path(), cfg)?;
21762174

21772175
// Move the old token location to the new one.
2178-
if let Some(token) = toml.as_table_mut().unwrap().remove("token") {
2176+
if let Some(token) = toml.remove("token") {
21792177
let map = HashMap::from([("token".to_string(), token)]);
2180-
toml.as_table_mut()
2181-
.unwrap()
2182-
.insert("registry".into(), map.into());
2178+
toml.insert("registry".into(), map.into());
21832179
}
21842180

21852181
if let Some(token) = token {
@@ -2226,17 +2222,16 @@ pub fn save_credentials(
22262222
};
22272223

22282224
if registry.is_some() {
2229-
if let Some(table) = toml.as_table_mut().unwrap().remove("registries") {
2225+
if let Some(table) = toml.remove("registries") {
22302226
let v = CV::from_toml(path_def, table)?;
22312227
value.merge(v, false)?;
22322228
}
22332229
}
2234-
toml.as_table_mut().unwrap().insert(key, value.into_toml());
2230+
toml.insert(key, value.into_toml());
22352231
} else {
22362232
// logout
2237-
let table = toml.as_table_mut().unwrap();
22382233
if let Some(registry) = registry {
2239-
if let Some(registries) = table.get_mut("registries") {
2234+
if let Some(registries) = toml.get_mut("registries") {
22402235
if let Some(reg) = registries.get_mut(registry) {
22412236
let rtable = reg.as_table_mut().ok_or_else(|| {
22422237
format_err!("expected `[registries.{}]` to be a table", registry)
@@ -2246,7 +2241,7 @@ pub fn save_credentials(
22462241
rtable.remove("secret-key-subject");
22472242
}
22482243
}
2249-
} else if let Some(registry) = table.get_mut("registry") {
2244+
} else if let Some(registry) = toml.get_mut("registry") {
22502245
let reg_table = registry
22512246
.as_table_mut()
22522247
.ok_or_else(|| format_err!("expected `[registry]` to be a table"))?;

src/cargo/util/config/target.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::util::CargoResult;
44
use serde::Deserialize;
55
use std::collections::{BTreeMap, HashMap};
66
use std::path::PathBuf;
7-
use toml_edit::easy as toml;
87

98
/// Config definition of a `[target.'cfg(…)']` table.
109
///

src/cargo/util/toml/mod.rs

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ use lazycell::LazyCell;
1313
use log::{debug, trace};
1414
use semver::{self, VersionReq};
1515
use serde::de;
16+
use serde::de::IntoDeserializer as _;
1617
use serde::ser;
1718
use serde::{Deserialize, Serialize};
18-
use toml_edit::easy as toml;
1919
use url::Url;
2020

2121
use crate::core::compiler::{CompileKind, CompileTarget};
@@ -36,9 +36,6 @@ use crate::util::{
3636
mod targets;
3737
use self::targets::targets;
3838

39-
pub use toml_edit::de::Error as TomlDeError;
40-
pub use toml_edit::TomlError as TomlEditError;
41-
4239
/// Loads a `Cargo.toml` from a file on disk.
4340
///
4441
/// This could result in a real or virtual manifest being returned.
@@ -90,21 +87,16 @@ pub fn read_manifest_from_str(
9087
// Provide a helpful error message for a common user error.
9188
if let Some(package) = toml.get("package").or_else(|| toml.get("project")) {
9289
if let Some(feats) = package.get("cargo-features") {
93-
let mut feats = feats.clone();
94-
if let Some(value) = feats.as_value_mut() {
95-
// Only keep formatting inside of the `[]` and not formatting around it
96-
value.decor_mut().clear();
97-
}
9890
bail!(
9991
"cargo-features = {} was found in the wrong location: it \
10092
should be set at the top of Cargo.toml before any tables",
101-
feats.to_string()
93+
feats
10294
);
10395
}
10496
}
10597

10698
let mut unused = BTreeSet::new();
107-
let manifest: TomlManifest = serde_ignored::deserialize(toml, |path| {
99+
let manifest: TomlManifest = serde_ignored::deserialize(toml.into_deserializer(), |path| {
108100
let mut key = String::new();
109101
stringify(&mut key, &path);
110102
unused.insert(key);
@@ -186,23 +178,7 @@ pub fn read_manifest_from_str(
186178
}
187179
}
188180

189-
/// Attempts to parse a string into a [`toml::Value`]. This is not specific to any
190-
/// particular kind of TOML file.
191-
///
192-
/// The purpose of this wrapper is to detect invalid TOML which was previously
193-
/// accepted and display a warning to the user in that case. The `file` and `config`
194-
/// parameters are only used by this fallback path.
195-
pub fn parse(toml: &str, _file: &Path, _config: &Config) -> CargoResult<toml::Value> {
196-
// At the moment, no compatibility checks are needed.
197-
toml.parse()
198-
.map_err(|e| anyhow::Error::from(e).context("could not parse input as TOML"))
199-
}
200-
201-
pub fn parse_document(
202-
toml: &str,
203-
_file: &Path,
204-
_config: &Config,
205-
) -> CargoResult<toml_edit::Document> {
181+
pub fn parse_document(toml: &str, _file: &Path, _config: &Config) -> CargoResult<toml::Table> {
206182
// At the moment, no compatibility checks are needed.
207183
toml.parse()
208184
.map_err(|e| anyhow::Error::from(e).context("could not parse input as TOML"))

0 commit comments

Comments
 (0)