From 6ffef660837ec7ee4c156aad36ca3b366eeb9e52 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 19 Jan 2023 15:26:28 -0600 Subject: [PATCH] chore: Update to toml v0.6, toml_edit v0.18 `toml` replaces `toml_edit::easy`, using `toml_edit` as its parser. --- Cargo.toml | 3 +- benches/capture/Cargo.toml | 2 +- benches/capture/src/main.rs | 1 - crates/cargo-test-support/Cargo.toml | 2 +- crates/cargo-test-support/src/registry.rs | 11 ++- src/cargo/core/manifest.rs | 1 - src/cargo/core/package.rs | 1 - src/cargo/core/workspace.rs | 1 - src/cargo/ops/cargo_config.rs | 3 +- src/cargo/ops/cargo_new.rs | 1 - src/cargo/ops/cargo_output_metadata.rs | 1 - .../ops/common_for_install_and_uninstall.rs | 1 - src/cargo/ops/lockfile.rs | 21 ++--- src/cargo/ops/vendor.rs | 1 - src/cargo/util/config/key.rs | 2 +- src/cargo/util/config/mod.rs | 53 +++++------ src/cargo/util/config/target.rs | 1 - src/cargo/util/toml/mod.rs | 32 +------ tests/testsuite/bad_config.rs | 26 +++--- tests/testsuite/build.rs | 14 +-- .../cargo_add/invalid_manifest/stderr.log | 3 +- tests/testsuite/cargo_alias_config.rs | 4 +- tests/testsuite/config.rs | 93 ++++++++++--------- tests/testsuite/config_cli.rs | 6 +- tests/testsuite/git.rs | 3 +- .../testsuite/inheritable_workspace_fields.rs | 7 +- tests/testsuite/install.rs | 3 +- tests/testsuite/install_upgrade.rs | 1 - tests/testsuite/login.rs | 10 +- tests/testsuite/logout.rs | 3 +- tests/testsuite/metadata.rs | 9 +- tests/testsuite/patch.rs | 9 +- tests/testsuite/workspaces.rs | 3 +- 33 files changed, 150 insertions(+), 182 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9b96a75339c7..31e4c190a6cc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -66,7 +66,8 @@ tar = { version = "0.4.38", default-features = false } tempfile = "3.0" termcolor = "1.1" time = { version = "0.3", features = ["parsing", "formatting"]} -toml_edit = { version = "0.15.0", features = ["serde", "easy", "perf"] } +toml_edit = "0.19.0" +toml = "0.7.0" unicode-xid = "0.2.0" url = "2.2.2" walkdir = "2.2" diff --git a/benches/capture/Cargo.toml b/benches/capture/Cargo.toml index 3ff3e70a1ac9..25a901777ff6 100644 --- a/benches/capture/Cargo.toml +++ b/benches/capture/Cargo.toml @@ -9,4 +9,4 @@ description = "Tool for capturing a real-world workspace for benchmarking." cargo_metadata = "0.14.0" flate2 = { version = "1.0.3", default-features = false, features = ["zlib"] } tar = { version = "0.4.38", default-features = false } -toml_edit = { version = "0.15.0", features = ["serde", "easy", "perf"] } +toml = "0.7.0" diff --git a/benches/capture/src/main.rs b/benches/capture/src/main.rs index 8656c63c3ee4..f6f02c4ba051 100644 --- a/benches/capture/src/main.rs +++ b/benches/capture/src/main.rs @@ -8,7 +8,6 @@ use flate2::{Compression, GzBuilder}; use std::fs; use std::path::{Path, PathBuf}; use std::process::Command; -use toml_edit::easy as toml; fn main() { let force = std::env::args().any(|arg| arg == "-f"); diff --git a/crates/cargo-test-support/Cargo.toml b/crates/cargo-test-support/Cargo.toml index 89eb94a5ef7d..e0512b971c54 100644 --- a/crates/cargo-test-support/Cargo.toml +++ b/crates/cargo-test-support/Cargo.toml @@ -25,7 +25,7 @@ serde = { version = "1.0.123", features = ["derive"] } serde_json = "1.0" tar = { version = "0.4.38", default-features = false } termcolor = "1.1.2" -toml_edit = { version = "0.15.0", features = ["serde", "easy", "perf"] } +toml = "0.7.0" url = "2.2.2" [target.'cfg(windows)'.dependencies] diff --git a/crates/cargo-test-support/src/registry.rs b/crates/cargo-test-support/src/registry.rs index 7574151ab652..a9d458c04695 100644 --- a/crates/cargo-test-support/src/registry.rs +++ b/crates/cargo-test-support/src/registry.rs @@ -1391,10 +1391,13 @@ impl Package { let mut manifest = String::new(); if !self.cargo_features.is_empty() { - manifest.push_str(&format!( - "cargo-features = {}\n\n", - toml_edit::ser::to_item(&self.cargo_features).unwrap() - )); + let mut features = String::new(); + serde::Serialize::serialize( + &self.cargo_features, + toml::ser::ValueSerializer::new(&mut features), + ) + .unwrap(); + manifest.push_str(&format!("cargo-features = {}\n\n", features)); } manifest.push_str(&format!( diff --git a/src/cargo/core/manifest.rs b/src/cargo/core/manifest.rs index c37dd1cb4558..182882dad75d 100644 --- a/src/cargo/core/manifest.rs +++ b/src/cargo/core/manifest.rs @@ -9,7 +9,6 @@ use anyhow::Context as _; use semver::Version; use serde::ser; use serde::Serialize; -use toml_edit::easy as toml; use url::Url; use crate::core::compiler::rustdoc::RustdocScrapeExamples; diff --git a/src/cargo/core/package.rs b/src/cargo/core/package.rs index 1c7532cb3e6e..29a768c4731c 100644 --- a/src/cargo/core/package.rs +++ b/src/cargo/core/package.rs @@ -16,7 +16,6 @@ use lazycell::LazyCell; use log::{debug, warn}; use semver::Version; use serde::Serialize; -use toml_edit::easy as toml; use crate::core::compiler::{CompileKind, RustcTargetData}; use crate::core::dependency::DepKind; diff --git a/src/cargo/core/workspace.rs b/src/cargo/core/workspace.rs index 023da986b693..12b78a69c592 100644 --- a/src/cargo/core/workspace.rs +++ b/src/cargo/core/workspace.rs @@ -8,7 +8,6 @@ use anyhow::{anyhow, bail, Context as _}; use glob::glob; use itertools::Itertools; use log::debug; -use toml_edit::easy as toml; use url::Url; use crate::core::compiler::Unit; diff --git a/src/cargo/ops/cargo_config.rs b/src/cargo/ops/cargo_config.rs index 2ee0e231b419..f27ed22da920 100644 --- a/src/cargo/ops/cargo_config.rs +++ b/src/cargo/ops/cargo_config.rs @@ -137,7 +137,8 @@ fn print_toml(config: &Config, opts: &GetOptions<'_>, key: &ConfigKey, cv: &CV) drop_println!( config, " {}, # {}", - toml_edit::ser::to_item(&val).unwrap(), + serde::Serialize::serialize(val, toml_edit::ser::ValueSerializer::new()) + .unwrap(), def ); } diff --git a/src/cargo/ops/cargo_new.rs b/src/cargo/ops/cargo_new.rs index b7ec89cba0d3..e2d493796150 100644 --- a/src/cargo/ops/cargo_new.rs +++ b/src/cargo/ops/cargo_new.rs @@ -12,7 +12,6 @@ use std::io::{BufRead, BufReader, ErrorKind}; use std::path::{Path, PathBuf}; use std::str::FromStr; use std::{fmt, slice}; -use toml_edit::easy as toml; #[derive(Clone, Copy, Debug, PartialEq)] pub enum VersionControl { diff --git a/src/cargo/ops/cargo_output_metadata.rs b/src/cargo/ops/cargo_output_metadata.rs index c71cfaa1e2e9..9d52fa09ad7c 100644 --- a/src/cargo/ops/cargo_output_metadata.rs +++ b/src/cargo/ops/cargo_output_metadata.rs @@ -11,7 +11,6 @@ use cargo_platform::Platform; use serde::Serialize; use std::collections::BTreeMap; use std::path::PathBuf; -use toml_edit::easy as toml; const VERSION: u32 = 1; diff --git a/src/cargo/ops/common_for_install_and_uninstall.rs b/src/cargo/ops/common_for_install_and_uninstall.rs index 078b8b20d9d4..8da70ce1cdb3 100644 --- a/src/cargo/ops/common_for_install_and_uninstall.rs +++ b/src/cargo/ops/common_for_install_and_uninstall.rs @@ -9,7 +9,6 @@ use std::task::Poll; use anyhow::{bail, format_err, Context as _}; use ops::FilterRule; use serde::{Deserialize, Serialize}; -use toml_edit::easy as toml; use crate::core::compiler::{DirtyReason, Freshness}; use crate::core::Target; diff --git a/src/cargo/ops/lockfile.rs b/src/cargo/ops/lockfile.rs index 2a1b1db39ddf..e11e492af305 100644 --- a/src/cargo/ops/lockfile.rs +++ b/src/cargo/ops/lockfile.rs @@ -6,7 +6,6 @@ use crate::util::toml as cargo_toml; use crate::util::Filesystem; use anyhow::Context as _; -use toml_edit::easy as toml; pub fn load_pkg_lockfile(ws: &Workspace<'_>) -> CargoResult> { if !ws.root().join("Cargo.lock").exists() { @@ -21,7 +20,7 @@ pub fn load_pkg_lockfile(ws: &Workspace<'_>) -> CargoResult> { .with_context(|| format!("failed to read file: {}", f.path().display()))?; let resolve = (|| -> CargoResult> { - let resolve: toml::Value = cargo_toml::parse(&s, f.path(), ws.config())?; + let resolve: toml::Table = cargo_toml::parse_document(&s, f.path(), ws.config())?; let v: resolver::EncodableResolve = resolve.try_into()?; Ok(Some(v.into_resolve(&s, ws)?)) })() @@ -101,7 +100,7 @@ fn resolve_to_string_orig( } fn serialize_resolve(resolve: &Resolve, orig: Option<&str>) -> String { - let toml = toml_edit::ser::to_item(resolve).unwrap(); + let toml = toml::Table::try_from(resolve).unwrap(); let mut out = String::new(); @@ -140,7 +139,7 @@ fn serialize_resolve(resolve: &Resolve, orig: Option<&str>) -> String { let deps = toml["package"].as_array().unwrap(); for dep in deps { - let dep = dep.as_inline_table().unwrap(); + let dep = dep.as_table().unwrap(); out.push_str("[[package]]\n"); emit_package(dep, &mut out); @@ -150,7 +149,7 @@ fn serialize_resolve(resolve: &Resolve, orig: Option<&str>) -> String { let list = patch["unused"].as_array().unwrap(); for entry in list { out.push_str("[[patch.unused]]\n"); - emit_package(entry.as_inline_table().unwrap(), &mut out); + emit_package(entry.as_table().unwrap(), &mut out); out.push('\n'); } } @@ -160,11 +159,11 @@ fn serialize_resolve(resolve: &Resolve, orig: Option<&str>) -> String { // (which `toml_edit::Table::to_string` only shows) // 2. We need to ensure all children tables have `metadata.` prefix let meta_table = meta - .clone() - .into_table() - .expect("validation ensures this is a table"); - let mut meta_doc = toml_edit::Document::new(); - meta_doc["metadata"] = toml_edit::Item::Table(meta_table); + .as_table() + .expect("validation ensures this is a table") + .clone(); + let mut meta_doc = toml::Table::new(); + meta_doc.insert("metadata".to_owned(), toml::Value::Table(meta_table)); out.push_str(&meta_doc.to_string()); } @@ -200,7 +199,7 @@ fn are_equal_lockfiles(orig: &str, current: &str, ws: &Workspace<'_>) -> bool { orig.lines().eq(current.lines()) } -fn emit_package(dep: &toml_edit::InlineTable, out: &mut String) { +fn emit_package(dep: &toml::Table, out: &mut String) { out.push_str(&format!("name = {}\n", &dep["name"])); out.push_str(&format!("version = {}\n", &dep["version"])); diff --git a/src/cargo/ops/vendor.rs b/src/cargo/ops/vendor.rs index 23c538e0f526..8c507d87b91f 100644 --- a/src/cargo/ops/vendor.rs +++ b/src/cargo/ops/vendor.rs @@ -14,7 +14,6 @@ use std::ffi::OsStr; use std::fs::{self, File, OpenOptions}; use std::io::{Read, Write}; use std::path::{Path, PathBuf}; -use toml_edit::easy as toml; pub struct VendorOptions<'a> { pub no_delete: bool, diff --git a/src/cargo/util/config/key.rs b/src/cargo/util/config/key.rs index 181b7c56a9ff..228d8584484c 100644 --- a/src/cargo/util/config/key.rs +++ b/src/cargo/util/config/key.rs @@ -111,6 +111,6 @@ fn escape_key_part<'a>(part: &'a str) -> Cow<'a, str> { Cow::Borrowed(part) } else { // This is a bit messy, but toml doesn't expose a function to do this. - Cow::Owned(toml_edit::Value::from(part).to_string()) + Cow::Owned(toml::Value::from(part).to_string()) } } diff --git a/src/cargo/util/config/mod.rs b/src/cargo/util/config/mod.rs index 53badb21287b..6ac5e47741de 100644 --- a/src/cargo/util/config/mod.rs +++ b/src/cargo/util/config/mod.rs @@ -80,8 +80,9 @@ use anyhow::{anyhow, bail, format_err, Context as _}; use cargo_util::paths; use curl::easy::Easy; use lazycell::LazyCell; +use serde::de::IntoDeserializer as _; use serde::Deserialize; -use toml_edit::{easy as toml, Item}; +use toml_edit::Item; use url::Url; mod de; @@ -895,17 +896,11 @@ impl Config { let def = Definition::Environment(key.as_env_key().to_string()); if self.cli_unstable().advanced_env && env_val.starts_with('[') && env_val.ends_with(']') { // Parse an environment string as a TOML array. - let toml_s = format!("value={}", env_val); - let toml_v: toml::Value = toml::de::from_str(&toml_s).map_err(|e| { - ConfigError::new(format!("could not parse TOML list: {}", e), def.clone()) - })?; - let values = toml_v - .as_table() - .unwrap() - .get("value") - .unwrap() - .as_array() - .expect("env var was not array"); + let toml_v = toml::Value::deserialize(toml::de::ValueDeserializer::new(&env_val)) + .map_err(|e| { + ConfigError::new(format!("could not parse TOML list: {}", e), def.clone()) + })?; + let values = toml_v.as_array().expect("env var was not array"); for value in values { // TODO: support other types. let s = value.as_str().ok_or_else(|| { @@ -1180,14 +1175,14 @@ impl Config { } let contents = fs::read_to_string(path) .with_context(|| format!("failed to read configuration file `{}`", path.display()))?; - let toml = cargo_toml::parse(&contents, path, self).with_context(|| { + let toml = cargo_toml::parse_document(&contents, path, self).with_context(|| { format!("could not parse TOML configuration in `{}`", path.display()) })?; let def = match why_load { WhyLoad::Cli => Definition::Cli(Some(path.into())), WhyLoad::FileDiscovery => Definition::Path(path.into()), }; - let value = CV::from_toml(def, toml).with_context(|| { + let value = CV::from_toml(def, toml::Value::Table(toml)).with_context(|| { format!( "failed to load TOML configuration from `{}`", path.display() @@ -1302,8 +1297,10 @@ impl Config { format!("failed to parse value from --config argument `{arg}` as a dotted key expression") })?; fn non_empty_decor(d: &toml_edit::Decor) -> bool { - d.prefix().map_or(false, |p| !p.trim().is_empty()) - || d.suffix().map_or(false, |s| !s.trim().is_empty()) + d.prefix() + .map_or(false, |p| !p.as_str().unwrap_or_default().trim().is_empty()) + || d.suffix() + .map_or(false, |s| !s.as_str().unwrap_or_default().trim().is_empty()) } let ok = { let mut got_to_value = false; @@ -1363,9 +1360,10 @@ impl Config { ); } - let toml_v: toml::Value = toml::from_document(doc).with_context(|| { - format!("failed to parse value from --config argument `{arg}`") - })?; + let toml_v: toml::Value = toml::Value::deserialize(doc.into_deserializer()) + .with_context(|| { + format!("failed to parse value from --config argument `{arg}`") + })?; if toml_v .get("registry") @@ -2171,14 +2169,12 @@ pub fn save_credentials( ) })?; - let mut toml = cargo_toml::parse(&contents, file.path(), cfg)?; + let mut toml = cargo_toml::parse_document(&contents, file.path(), cfg)?; // Move the old token location to the new one. - if let Some(token) = toml.as_table_mut().unwrap().remove("token") { + if let Some(token) = toml.remove("token") { let map = HashMap::from([("token".to_string(), token)]); - toml.as_table_mut() - .unwrap() - .insert("registry".into(), map.into()); + toml.insert("registry".into(), map.into()); } if let Some(token) = token { @@ -2225,17 +2221,16 @@ pub fn save_credentials( }; if registry.is_some() { - if let Some(table) = toml.as_table_mut().unwrap().remove("registries") { + if let Some(table) = toml.remove("registries") { let v = CV::from_toml(path_def, table)?; value.merge(v, false)?; } } - toml.as_table_mut().unwrap().insert(key, value.into_toml()); + toml.insert(key, value.into_toml()); } else { // logout - let table = toml.as_table_mut().unwrap(); if let Some(registry) = registry { - if let Some(registries) = table.get_mut("registries") { + if let Some(registries) = toml.get_mut("registries") { if let Some(reg) = registries.get_mut(registry) { let rtable = reg.as_table_mut().ok_or_else(|| { format_err!("expected `[registries.{}]` to be a table", registry) @@ -2245,7 +2240,7 @@ pub fn save_credentials( rtable.remove("secret-key-subject"); } } - } else if let Some(registry) = table.get_mut("registry") { + } else if let Some(registry) = toml.get_mut("registry") { let reg_table = registry .as_table_mut() .ok_or_else(|| format_err!("expected `[registry]` to be a table"))?; diff --git a/src/cargo/util/config/target.rs b/src/cargo/util/config/target.rs index 8190529a6860..a7f2f3ef2694 100644 --- a/src/cargo/util/config/target.rs +++ b/src/cargo/util/config/target.rs @@ -4,7 +4,6 @@ use crate::util::CargoResult; use serde::Deserialize; use std::collections::{BTreeMap, HashMap}; use std::path::PathBuf; -use toml_edit::easy as toml; /// Config definition of a `[target.'cfg(…)']` table. /// diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index bc8db23cedfe..6b429d6a151e 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -13,9 +13,9 @@ use lazycell::LazyCell; use log::{debug, trace}; use semver::{self, VersionReq}; use serde::de; +use serde::de::IntoDeserializer as _; use serde::ser; use serde::{Deserialize, Serialize}; -use toml_edit::easy as toml; use url::Url; use crate::core::compiler::{CompileKind, CompileTarget}; @@ -36,9 +36,6 @@ use crate::util::{ mod targets; use self::targets::targets; -pub use toml_edit::de::Error as TomlDeError; -pub use toml_edit::TomlError as TomlEditError; - /// Loads a `Cargo.toml` from a file on disk. /// /// This could result in a real or virtual manifest being returned. @@ -90,21 +87,16 @@ pub fn read_manifest_from_str( // Provide a helpful error message for a common user error. if let Some(package) = toml.get("package").or_else(|| toml.get("project")) { if let Some(feats) = package.get("cargo-features") { - let mut feats = feats.clone(); - if let Some(value) = feats.as_value_mut() { - // Only keep formatting inside of the `[]` and not formatting around it - value.decor_mut().clear(); - } bail!( "cargo-features = {} was found in the wrong location: it \ should be set at the top of Cargo.toml before any tables", - feats.to_string() + feats ); } } let mut unused = BTreeSet::new(); - let manifest: TomlManifest = serde_ignored::deserialize(toml, |path| { + let manifest: TomlManifest = serde_ignored::deserialize(toml.into_deserializer(), |path| { let mut key = String::new(); stringify(&mut key, &path); unused.insert(key); @@ -178,23 +170,7 @@ pub fn read_manifest_from_str( } } -/// Attempts to parse a string into a [`toml::Value`]. This is not specific to any -/// particular kind of TOML file. -/// -/// The purpose of this wrapper is to detect invalid TOML which was previously -/// accepted and display a warning to the user in that case. The `file` and `config` -/// parameters are only used by this fallback path. -pub fn parse(toml: &str, _file: &Path, _config: &Config) -> CargoResult { - // At the moment, no compatibility checks are needed. - toml.parse() - .map_err(|e| anyhow::Error::from(e).context("could not parse input as TOML")) -} - -pub fn parse_document( - toml: &str, - _file: &Path, - _config: &Config, -) -> CargoResult { +pub fn parse_document(toml: &str, _file: &Path, _config: &Config) -> CargoResult { // At the moment, no compatibility checks are needed. toml.parse() .map_err(|e| anyhow::Error::from(e).context("could not parse input as TOML")) diff --git a/tests/testsuite/bad_config.rs b/tests/testsuite/bad_config.rs index 179474658a08..a6fe93cf39ab 100644 --- a/tests/testsuite/bad_config.rs +++ b/tests/testsuite/bad_config.rs @@ -178,8 +178,7 @@ Caused by: | 1 | 4 | ^ - Unexpected end of input - Expected `.` or `=` + expected `.`, `=` ", ) .run(); @@ -199,7 +198,8 @@ fn bad_cargo_lock() { [ERROR] failed to parse lock file at: [..]Cargo.lock Caused by: - missing field `name` for key `package` + missing field `name` + in `package` ", ) .run(); @@ -302,7 +302,8 @@ fn bad_source_in_cargo_lock() { [ERROR] failed to parse lock file at: [..] Caused by: - invalid source `You shall not parse` for key `package.source` + invalid source `You shall not parse` + in `package.source` ", ) .run(); @@ -429,9 +430,8 @@ Caused by: | 8 | native = { | ^ - Unexpected ` - ` - Expected key + invalid inline table + expected `}` ", ) .run(); @@ -785,9 +785,8 @@ Caused by: | 1 | [bar] baz = 2 | ^ - Unexpected `b` - Expected newline or end of input - While parsing a Table Header + invalid table header + expected newline, `#` ", ) .run(); @@ -1264,6 +1263,7 @@ error: failed to parse manifest at `[..]` Caused by: invalid type: integer `3`, expected a version string like [..] + in `dependencies.bar` ", ) .run(); @@ -1294,7 +1294,8 @@ fn bad_debuginfo() { error: failed to parse manifest at `[..]` Caused by: - expected a boolean or an integer for [..] + expected a boolean or an integer + in `profile.dev.debug` ", ) .run(); @@ -1323,7 +1324,8 @@ fn bad_opt_level() { error: failed to parse manifest at `[..]` Caused by: - expected a boolean or a string for key [..] + expected a boolean or a string + in `package.build` ", ) .run(); diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index 42238f2cff07..a27a70a22b5f 100644 --- a/tests/testsuite/build.rs +++ b/tests/testsuite/build.rs @@ -202,8 +202,8 @@ Caused by: | 3 | foo = bar | ^ - Unexpected `b` - Expected quoted string + invalid string + expected `\"`, `'` ", ) .run(); @@ -227,8 +227,8 @@ Caused by: | 1 | a = bar | ^ - Unexpected `b` - Expected quoted string + invalid string + expected `\"`, `'` ", ) .run(); @@ -282,7 +282,8 @@ fn cargo_compile_with_invalid_version() { [ERROR] failed to parse manifest at `[..]` Caused by: - unexpected end of input while parsing minor version number for key `package.version` + unexpected end of input while parsing minor version number + in `package.version` ", ) .run(); @@ -2953,8 +2954,7 @@ Caused by: | 1 | this is not valid toml | ^ - Unexpected `i` - Expected `.` or `=` + expected `.`, `=` ", ) .run(); diff --git a/tests/testsuite/cargo_add/invalid_manifest/stderr.log b/tests/testsuite/cargo_add/invalid_manifest/stderr.log index 83bfc5e4eaa6..3dabde3491e4 100644 --- a/tests/testsuite/cargo_add/invalid_manifest/stderr.log +++ b/tests/testsuite/cargo_add/invalid_manifest/stderr.log @@ -8,4 +8,5 @@ Caused by: | 8 | key = invalid-value | ^ - Unexpected `v` + invalid string + expected `"`, `'` diff --git a/tests/testsuite/cargo_alias_config.rs b/tests/testsuite/cargo_alias_config.rs index f797acfc363d..fd4aec9177f4 100644 --- a/tests/testsuite/cargo_alias_config.rs +++ b/tests/testsuite/cargo_alias_config.rs @@ -60,8 +60,8 @@ Caused by: | 3 | b-cargo-test = ` | ^ - Unexpected ``` - Expected quoted string + invalid string + expected `\"`, `'` ", ) .run(); diff --git a/tests/testsuite/config.rs b/tests/testsuite/config.rs index d1487833f71a..be3f312f1ab9 100644 --- a/tests/testsuite/config.rs +++ b/tests/testsuite/config.rs @@ -3,7 +3,7 @@ use cargo::core::{PackageIdSpec, Shell}; use cargo::util::config::{self, Config, Definition, SslVersionConfig, StringList}; use cargo::util::interning::InternedString; -use cargo::util::toml::{self, VecStringOrBool as VSOB}; +use cargo::util::toml::{self as cargo_toml, VecStringOrBool as VSOB}; use cargo::CargoResult; use cargo_test_support::compare; use cargo_test_support::{panic_error, paths, project, symlink_supported, t}; @@ -352,17 +352,19 @@ lto = false .build(); // TODO: don't use actual `tomlprofile`. - let p: toml::TomlProfile = config.get("profile.dev").unwrap(); + let p: cargo_toml::TomlProfile = config.get("profile.dev").unwrap(); let mut packages = BTreeMap::new(); - let key = toml::ProfilePackageSpec::Spec(::cargo::core::PackageIdSpec::parse("bar").unwrap()); - let o_profile = toml::TomlProfile { - opt_level: Some(toml::TomlOptLevel("2".to_string())), + let key = + cargo_toml::ProfilePackageSpec::Spec(::cargo::core::PackageIdSpec::parse("bar").unwrap()); + let o_profile = cargo_toml::TomlProfile { + opt_level: Some(cargo_toml::TomlOptLevel("2".to_string())), codegen_units: Some(9), ..Default::default() }; packages.insert(key, o_profile); - let key = toml::ProfilePackageSpec::Spec(::cargo::core::PackageIdSpec::parse("env").unwrap()); - let o_profile = toml::TomlProfile { + let key = + cargo_toml::ProfilePackageSpec::Spec(::cargo::core::PackageIdSpec::parse("env").unwrap()); + let o_profile = cargo_toml::TomlProfile { codegen_units: Some(13), ..Default::default() }; @@ -370,19 +372,19 @@ lto = false assert_eq!( p, - toml::TomlProfile { - opt_level: Some(toml::TomlOptLevel("s".to_string())), - lto: Some(toml::StringOrBool::Bool(true)), + cargo_toml::TomlProfile { + opt_level: Some(cargo_toml::TomlOptLevel("s".to_string())), + lto: Some(cargo_toml::StringOrBool::Bool(true)), codegen_units: Some(5), - debug: Some(toml::U32OrBool::Bool(true)), + debug: Some(cargo_toml::U32OrBool::Bool(true)), debug_assertions: Some(true), rpath: Some(true), panic: Some("abort".to_string()), overflow_checks: Some(true), incremental: Some(true), package: Some(packages), - build_override: Some(Box::new(toml::TomlProfile { - opt_level: Some(toml::TomlOptLevel("1".to_string())), + build_override: Some(Box::new(cargo_toml::TomlProfile { + opt_level: Some(cargo_toml::TomlOptLevel("1".to_string())), codegen_units: Some(11), ..Default::default() })), @@ -390,11 +392,11 @@ lto = false } ); - let p: toml::TomlProfile = config.get("profile.no-lto").unwrap(); + let p: cargo_toml::TomlProfile = config.get("profile.no-lto").unwrap(); assert_eq!( p, - toml::TomlProfile { - lto: Some(toml::StringOrBool::Bool(false)), + cargo_toml::TomlProfile { + lto: Some(cargo_toml::StringOrBool::Bool(false)), dir_name: Some(InternedString::new("without-lto")), inherits: Some(InternedString::new("dev")), ..Default::default() @@ -408,24 +410,24 @@ fn profile_env_var_prefix() { let config = ConfigBuilder::new() .env("CARGO_PROFILE_DEV_DEBUG_ASSERTIONS", "false") .build(); - let p: toml::TomlProfile = config.get("profile.dev").unwrap(); + let p: cargo_toml::TomlProfile = config.get("profile.dev").unwrap(); assert_eq!(p.debug_assertions, Some(false)); assert_eq!(p.debug, None); let config = ConfigBuilder::new() .env("CARGO_PROFILE_DEV_DEBUG", "1") .build(); - let p: toml::TomlProfile = config.get("profile.dev").unwrap(); + let p: cargo_toml::TomlProfile = config.get("profile.dev").unwrap(); assert_eq!(p.debug_assertions, None); - assert_eq!(p.debug, Some(toml::U32OrBool::U32(1))); + assert_eq!(p.debug, Some(cargo_toml::U32OrBool::U32(1))); let config = ConfigBuilder::new() .env("CARGO_PROFILE_DEV_DEBUG_ASSERTIONS", "false") .env("CARGO_PROFILE_DEV_DEBUG", "1") .build(); - let p: toml::TomlProfile = config.get("profile.dev").unwrap(); + let p: cargo_toml::TomlProfile = config.get("profile.dev").unwrap(); assert_eq!(p.debug_assertions, Some(false)); - assert_eq!(p.debug, Some(toml::U32OrBool::U32(1))); + assert_eq!(p.debug, Some(cargo_toml::U32OrBool::U32(1))); } #[cargo_test] @@ -542,7 +544,9 @@ opt-level = 'foo' let config = new_config(); assert_error( - config.get::("profile.dev").unwrap_err(), + config + .get::("profile.dev") + .unwrap_err(), "\ error in [..]/.cargo/config: could not load config key `profile.dev.opt-level` @@ -555,7 +559,7 @@ Caused by: .build(); assert_error( - config.get::("profile.dev").unwrap_err(), + config.get::("profile.dev").unwrap_err(), "\ error in environment variable `CARGO_PROFILE_DEV_OPT_LEVEL`: could not load config key `profile.dev.opt-level` @@ -700,8 +704,7 @@ Caused by: | 1 | asdf | ^ -Unexpected end of input -Expected `.` or `=`", +expected `.`, `=`", ); } @@ -771,12 +774,12 @@ expected a list, but found a integer for `l3` in [..]/.cargo/config", assert_error( config.get::("bad-env").unwrap_err(), "\ -error in environment variable `CARGO_BAD_ENV`: could not parse TOML list: TOML parse error at line 1, column 8 +error in environment variable `CARGO_BAD_ENV`: could not parse TOML list: TOML parse error at line 1, column 2 | -1 | value=[zzz] - | ^ -Unexpected `z` -Expected newline or `#` +1 | [zzz] + | ^ +invalid array +expected `]` ", ); @@ -1070,8 +1073,7 @@ Caused by: | 3 | ssl-version.min = 'tlsv1.2' | ^ -Dotted key `ssl-version` attempted to extend non-table type (string) - +dotted key `ssl-version` attempted to extend non-table type (string) ", ); } @@ -1440,9 +1442,12 @@ strip = 'debuginfo' let config = new_config(); - let p: toml::TomlProfile = config.get("profile.release").unwrap(); + let p: cargo_toml::TomlProfile = config.get("profile.release").unwrap(); let strip = p.strip.unwrap(); - assert_eq!(strip, toml::StringOrBool::String("debuginfo".to_string())); + assert_eq!( + strip, + cargo_toml::StringOrBool::String("debuginfo".to_string()) + ); } #[cargo_test] @@ -1476,12 +1481,12 @@ fn cargo_target_empty_env() { #[cargo_test] fn all_profile_options() { // Check that all profile options can be serialized/deserialized. - let base_settings = toml::TomlProfile { - opt_level: Some(toml::TomlOptLevel("0".to_string())), - lto: Some(toml::StringOrBool::String("thin".to_string())), + let base_settings = cargo_toml::TomlProfile { + opt_level: Some(cargo_toml::TomlOptLevel("0".to_string())), + lto: Some(cargo_toml::StringOrBool::String("thin".to_string())), codegen_backend: Some(InternedString::new("example")), codegen_units: Some(123), - debug: Some(toml::U32OrBool::U32(1)), + debug: Some(cargo_toml::U32OrBool::U32(1)), split_debuginfo: Some("packed".to_string()), debug_assertions: Some(true), rpath: Some(true), @@ -1490,22 +1495,22 @@ fn all_profile_options() { incremental: Some(true), dir_name: Some(InternedString::new("dir_name")), inherits: Some(InternedString::new("debug")), - strip: Some(toml::StringOrBool::String("symbols".to_string())), + strip: Some(cargo_toml::StringOrBool::String("symbols".to_string())), package: None, build_override: None, rustflags: None, }; let mut overrides = BTreeMap::new(); - let key = toml::ProfilePackageSpec::Spec(PackageIdSpec::parse("foo").unwrap()); + let key = cargo_toml::ProfilePackageSpec::Spec(PackageIdSpec::parse("foo").unwrap()); overrides.insert(key, base_settings.clone()); - let profile = toml::TomlProfile { + let profile = cargo_toml::TomlProfile { build_override: Some(Box::new(base_settings.clone())), package: Some(overrides), ..base_settings }; - let profile_toml = toml_edit::easy::to_string(&profile).unwrap(); - let roundtrip: toml::TomlProfile = toml_edit::easy::from_str(&profile_toml).unwrap(); - let roundtrip_toml = toml_edit::easy::to_string(&roundtrip).unwrap(); + let profile_toml = toml::to_string(&profile).unwrap(); + let roundtrip: cargo_toml::TomlProfile = toml::from_str(&profile_toml).unwrap(); + let roundtrip_toml = toml::to_string(&roundtrip).unwrap(); compare::assert_match_exact(&profile_toml, &roundtrip_toml); } diff --git a/tests/testsuite/config_cli.rs b/tests/testsuite/config_cli.rs index be70b5da806d..1120e279d9dd 100644 --- a/tests/testsuite/config_cli.rs +++ b/tests/testsuite/config_cli.rs @@ -395,8 +395,7 @@ Caused by: | 1 | abc | ^ -Unexpected end of input -Expected `.` or `=` +expected `.`, `=` ", ); @@ -559,8 +558,7 @@ Caused by: | 1 | missing.toml | ^ -Unexpected end of input -Expected `.` or `=` +expected `.`, `=` ", ); } diff --git a/tests/testsuite/git.rs b/tests/testsuite/git.rs index 705069e0a988..8abd7f1caee8 100644 --- a/tests/testsuite/git.rs +++ b/tests/testsuite/git.rs @@ -2623,8 +2623,7 @@ Caused by: | 8 | categories = [\"algorithms\"] | ^ - Duplicate key `categories` in table `package` - + duplicate key `categories` in table `package` ", path2url(&git_root), path2url(&git_root), diff --git a/tests/testsuite/inheritable_workspace_fields.rs b/tests/testsuite/inheritable_workspace_fields.rs index 705036ab184f..d371c9f6de1d 100644 --- a/tests/testsuite/inheritable_workspace_fields.rs +++ b/tests/testsuite/inheritable_workspace_fields.rs @@ -1174,7 +1174,8 @@ fn error_workspace_false() { [ERROR] failed to parse manifest at `[CWD]/Cargo.toml` Caused by: - `workspace` cannot be false for key `package.description` + `workspace` cannot be false + in `package.description` ", ) .run(); @@ -1266,8 +1267,8 @@ Caused by: | 3 | members = [invalid toml | ^ - Unexpected `i` - Expected newline or `#` + invalid array + expected `]` ", ) .run(); diff --git a/tests/testsuite/install.rs b/tests/testsuite/install.rs index 9f17e2a5b667..7d93bd3ae51e 100644 --- a/tests/testsuite/install.rs +++ b/tests/testsuite/install.rs @@ -989,8 +989,7 @@ Caused by: | 1 | [..] | ^ - Unexpected `[..]` - Expected key or end of input + invalid key ", ) .run(); diff --git a/tests/testsuite/install_upgrade.rs b/tests/testsuite/install_upgrade.rs index f8678bbd68af..ae641ba98d20 100644 --- a/tests/testsuite/install_upgrade.rs +++ b/tests/testsuite/install_upgrade.rs @@ -6,7 +6,6 @@ use std::env; use std::fs; use std::path::PathBuf; use std::sync::atomic::{AtomicUsize, Ordering}; -use toml_edit::easy as toml; use cargo_test_support::install::{cargo_home, exe}; use cargo_test_support::paths::CargoPathExt; diff --git a/tests/testsuite/login.rs b/tests/testsuite/login.rs index 2a7fdbff2a80..2757e2ad4f4f 100644 --- a/tests/testsuite/login.rs +++ b/tests/testsuite/login.rs @@ -6,7 +6,6 @@ use cargo_test_support::registry::{self, RegistryBuilder}; use cargo_test_support::t; use std::fs; use std::path::PathBuf; -use toml_edit::easy as toml; const TOKEN: &str = "test-token"; const TOKEN2: &str = "test-token2"; @@ -33,12 +32,12 @@ fn check_token(expected_token: &str, registry: Option<&str>) -> bool { assert!(credentials.is_file()); let contents = fs::read_to_string(&credentials).unwrap(); - let toml: toml::Value = contents.parse().unwrap(); + let toml: toml::Table = contents.parse().unwrap(); - let token = match (registry, toml) { + let token = match registry { // A registry has been provided, so check that the token exists in a // table for the registry. - (Some(registry), toml::Value::Table(table)) => table + Some(registry) => toml .get("registries") .and_then(|registries_table| registries_table.get(registry)) .and_then(|registry_table| match registry_table.get("token") { @@ -46,14 +45,13 @@ fn check_token(expected_token: &str, registry: Option<&str>) -> bool { _ => None, }), // There is no registry provided, so check the global token instead. - (None, toml::Value::Table(table)) => table + None => toml .get("registry") .and_then(|registry_table| registry_table.get("token")) .and_then(|v| match v { toml::Value::String(ref token) => Some(token.as_str().to_string()), _ => None, }), - _ => None, }; if let Some(token_val) = token { diff --git a/tests/testsuite/logout.rs b/tests/testsuite/logout.rs index ee5b61023272..92b6f42a433b 100644 --- a/tests/testsuite/logout.rs +++ b/tests/testsuite/logout.rs @@ -4,7 +4,6 @@ use cargo_test_support::install::cargo_home; use cargo_test_support::registry::TestRegistry; use cargo_test_support::{cargo_process, registry}; use std::fs; -use toml_edit::easy as toml; #[cargo_test] fn gated() { @@ -26,7 +25,7 @@ the `cargo logout` command. fn check_config_token(registry: Option<&str>, should_be_set: bool) { let credentials = cargo_home().join("credentials.toml"); let contents = fs::read_to_string(&credentials).unwrap(); - let toml: toml::Value = contents.parse().unwrap(); + let toml: toml::Table = contents.parse().unwrap(); if let Some(registry) = registry { assert_eq!( toml.get("registries") diff --git a/tests/testsuite/metadata.rs b/tests/testsuite/metadata.rs index 441630bec435..888f47372178 100644 --- a/tests/testsuite/metadata.rs +++ b/tests/testsuite/metadata.rs @@ -1797,7 +1797,8 @@ fn cargo_metadata_with_invalid_authors_field() { r#"[ERROR] failed to parse manifest at `[..]` Caused by: - invalid type: string "", expected a sequence for key `package.authors`"#, + invalid type: string "", expected a sequence + in `package.authors`"#, ) .run(); } @@ -1821,7 +1822,8 @@ fn cargo_metadata_with_invalid_version_field() { r#"[ERROR] failed to parse manifest at `[..]` Caused by: - invalid type: integer `1`, expected SemVer version for key `package.version`"#, + invalid type: integer `1`, expected SemVer version + in `package.version`"#, ) .run(); } @@ -1845,7 +1847,8 @@ fn cargo_metadata_with_invalid_publish_field() { r#"[ERROR] failed to parse manifest at `[..]` Caused by: - invalid type: string "foo", expected a boolean or vector of strings for key `package.publish`"#, + invalid type: string "foo", expected a boolean or vector of strings + in `package.publish`"#, ) .run(); } diff --git a/tests/testsuite/patch.rs b/tests/testsuite/patch.rs index ca9300798113..e3a9d2e39337 100644 --- a/tests/testsuite/patch.rs +++ b/tests/testsuite/patch.rs @@ -5,7 +5,6 @@ use cargo_test_support::paths; use cargo_test_support::registry::{self, Package}; use cargo_test_support::{basic_manifest, project}; use std::fs; -use toml_edit::easy as toml; #[cargo_test] fn replace() { @@ -386,7 +385,7 @@ version. [..] // unused patch should be in the lock file let lock = p.read_lockfile(); - let toml: toml::Value = toml::from_str(&lock).unwrap(); + let toml: toml::Table = toml::from_str(&lock).unwrap(); assert_eq!(toml["patch"]["unused"].as_array().unwrap().len(), 1); assert_eq!(toml["patch"]["unused"][0]["name"].as_str(), Some("bar")); assert_eq!( @@ -494,7 +493,7 @@ fn prefer_patch_version() { // there should be no patch.unused in the toml file let lock = p.read_lockfile(); - let toml: toml::Value = toml::from_str(&lock).unwrap(); + let toml: toml::Table = toml::from_str(&lock).unwrap(); assert!(toml.get("patch").is_none()); } @@ -559,7 +558,7 @@ version. [..] // unused patch should be in the lock file let lock = p.read_lockfile(); - let toml: toml::Value = toml::from_str(&lock).unwrap(); + let toml: toml::Table = toml::from_str(&lock).unwrap(); assert_eq!(toml["patch"]["unused"].as_array().unwrap().len(), 1); assert_eq!(toml["patch"]["unused"][0]["name"].as_str(), Some("bar")); assert_eq!( @@ -1934,7 +1933,7 @@ fn update_unused_new_version() { .run(); // unused patch should be in the lock file let lock = p.read_lockfile(); - let toml: toml::Value = toml::from_str(&lock).unwrap(); + let toml: toml::Table = toml::from_str(&lock).unwrap(); assert_eq!(toml["patch"]["unused"].as_array().unwrap().len(), 1); assert_eq!(toml["patch"]["unused"][0]["name"].as_str(), Some("bar")); assert_eq!( diff --git a/tests/testsuite/workspaces.rs b/tests/testsuite/workspaces.rs index 58da0c0afce8..c4099ceed504 100644 --- a/tests/testsuite/workspaces.rs +++ b/tests/testsuite/workspaces.rs @@ -1098,8 +1098,7 @@ Caused by: | 1 | asdf | ^ - Unexpected end of input - Expected `.` or `=` + expected `.`, `=` Created binary (application) `bar` package ", )