mirror of
https://github.com/rust-lang/cargo
synced 2024-07-05 01:19:13 +00:00
refactor(toml): Resolve toml_edit deprecations
This commit is contained in:
parent
66b19adaa0
commit
c272cd7e37
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -3418,9 +3418,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "toml_edit"
|
||||
version = "0.22.6"
|
||||
version = "0.22.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2c1b5fd4128cc8d3e0cb74d4ed9a9cc7c7284becd4df68f5f940e1ad123606f6"
|
||||
checksum = "18769cd1cec395d70860ceb4d932812a0b4d06b1a4bb336745a4d21b9496e992"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"serde",
|
||||
|
|
|
@ -97,7 +97,7 @@ tempfile = "3.10.1"
|
|||
thiserror = "1.0.57"
|
||||
time = { version = "0.3", features = ["parsing", "formatting", "serde"] }
|
||||
toml = "0.8.10"
|
||||
toml_edit = { version = "0.22.6", features = ["serde"] }
|
||||
toml_edit = { version = "0.22.7", features = ["serde"] }
|
||||
tracing = "0.1.40" # be compatible with rustc_log: https://github.com/rust-lang/rust/blob/e51e98dde6a/compiler/rustc_log/Cargo.toml#L9
|
||||
tracing-chrome = "0.7.1"
|
||||
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
use std::fmt::Write as _;
|
||||
use std::path::PathBuf;
|
||||
use std::process;
|
||||
use toml_edit::Document;
|
||||
use toml_edit::DocumentMut;
|
||||
|
||||
fn main() {
|
||||
let pkg_root = std::env!("CARGO_MANIFEST_DIR");
|
||||
|
@ -31,7 +31,7 @@ fn main() {
|
|||
let mut passed = 0;
|
||||
|
||||
let toml = std::fs::read_to_string(path).expect("read from file");
|
||||
let doc = toml.parse::<Document>().expect("a toml");
|
||||
let doc = toml.parse::<DocumentMut>().expect("a toml");
|
||||
let autolabel = doc["autolabel"].as_table().expect("a toml table");
|
||||
|
||||
for (label, value) in autolabel.iter() {
|
||||
|
|
|
@ -160,7 +160,7 @@ fn parse_section(args: &ArgMatches) -> DepTable {
|
|||
/// Clean up the workspace.dependencies, profile, patch, and replace sections of the root manifest
|
||||
/// by removing dependencies which no longer have a reference to them.
|
||||
fn gc_workspace(workspace: &Workspace<'_>) -> CargoResult<()> {
|
||||
let mut manifest: toml_edit::Document =
|
||||
let mut manifest: toml_edit::DocumentMut =
|
||||
cargo_util::paths::read(workspace.root_manifest())?.parse()?;
|
||||
let mut is_modified = true;
|
||||
|
||||
|
@ -315,7 +315,7 @@ fn spec_has_match(
|
|||
|
||||
/// Removes unused patches from the manifest
|
||||
fn gc_unused_patches(workspace: &Workspace<'_>, resolve: &Resolve) -> CargoResult<bool> {
|
||||
let mut manifest: toml_edit::Document =
|
||||
let mut manifest: toml_edit::DocumentMut =
|
||||
cargo_util::paths::read(workspace.root_manifest())?.parse()?;
|
||||
let mut modified = false;
|
||||
|
||||
|
|
|
@ -768,7 +768,7 @@ fn mk(gctx: &GlobalContext, opts: &MkOptions<'_>) -> CargoResult<()> {
|
|||
write_ignore_file(path, &ignore, vcs)?;
|
||||
|
||||
// Create `Cargo.toml` file with necessary `[lib]` and `[[bin]]` sections, if needed.
|
||||
let mut manifest = toml_edit::Document::new();
|
||||
let mut manifest = toml_edit::DocumentMut::new();
|
||||
manifest["package"] = toml_edit::Item::Table(toml_edit::Table::new());
|
||||
manifest["package"]["name"] = toml_edit::value(name);
|
||||
manifest["package"]["version"] = toml_edit::value("0.1.0");
|
||||
|
@ -814,7 +814,7 @@ fn mk(gctx: &GlobalContext, opts: &MkOptions<'_>) -> CargoResult<()> {
|
|||
// Sometimes the root manifest is not a valid manifest, so we only try to parse it if it is.
|
||||
// This should not block the creation of the new project. It is only a best effort to
|
||||
// inherit the workspace package keys.
|
||||
if let Ok(mut workspace_document) = root_manifest.parse::<toml_edit::Document>() {
|
||||
if let Ok(mut workspace_document) = root_manifest.parse::<toml_edit::DocumentMut>() {
|
||||
let display_path = get_display_path(&root_manifest_path, &path)?;
|
||||
let can_be_a_member = can_be_workspace_member(&display_path, &workspace_document)?;
|
||||
// Only try to inherit the workspace stuff if the new package can be a member of the workspace.
|
||||
|
@ -933,14 +933,14 @@ mod tests {
|
|||
// If the option is set, keep the value from the manifest.
|
||||
fn update_manifest_with_inherited_workspace_package_keys(
|
||||
opts: &MkOptions<'_>,
|
||||
manifest: &mut toml_edit::Document,
|
||||
manifest: &mut toml_edit::DocumentMut,
|
||||
workspace_package_keys: &toml_edit::Table,
|
||||
) {
|
||||
if workspace_package_keys.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
let try_remove_and_inherit_package_key = |key: &str, manifest: &mut toml_edit::Document| {
|
||||
let try_remove_and_inherit_package_key = |key: &str, manifest: &mut toml_edit::DocumentMut| {
|
||||
let package = manifest["package"]
|
||||
.as_table_mut()
|
||||
.expect("package is a table");
|
||||
|
@ -974,7 +974,7 @@ fn update_manifest_with_inherited_workspace_package_keys(
|
|||
/// with the new package in it.
|
||||
fn update_manifest_with_new_member(
|
||||
root_manifest_path: &Path,
|
||||
workspace_document: &mut toml_edit::Document,
|
||||
workspace_document: &mut toml_edit::DocumentMut,
|
||||
display_path: &str,
|
||||
) -> CargoResult<bool> {
|
||||
// If the members element already exist, check if one of the patterns
|
||||
|
@ -1048,7 +1048,7 @@ fn get_display_path(root_manifest_path: &Path, package_path: &Path) -> CargoResu
|
|||
// Check if the package can be a member of the workspace.
|
||||
fn can_be_workspace_member(
|
||||
display_path: &str,
|
||||
workspace_document: &toml_edit::Document,
|
||||
workspace_document: &toml_edit::DocumentMut,
|
||||
) -> CargoResult<bool> {
|
||||
if let Some(exclude) = workspace_document
|
||||
.get("workspace")
|
||||
|
|
|
@ -1365,9 +1365,9 @@ impl GlobalContext {
|
|||
// We only want to allow "dotted key" (see https://toml.io/en/v1.0.0#keys)
|
||||
// expressions followed by a value that's not an "inline table"
|
||||
// (https://toml.io/en/v1.0.0#inline-table). Easiest way to check for that is to
|
||||
// parse the value as a toml_edit::Document, and check that the (single)
|
||||
// parse the value as a toml_edit::DocumentMut, and check that the (single)
|
||||
// inner-most table is set via dotted keys.
|
||||
let doc: toml_edit::Document = arg.parse().with_context(|| {
|
||||
let doc: toml_edit::DocumentMut = arg.parse().with_context(|| {
|
||||
format!("failed to parse value from --config argument `{arg}` as a dotted key expression")
|
||||
})?;
|
||||
fn non_empty(d: Option<&toml_edit::RawString>) -> bool {
|
||||
|
|
|
@ -82,7 +82,7 @@ impl From<DepKind> for DepTable {
|
|||
#[derive(Debug, Clone)]
|
||||
pub struct Manifest {
|
||||
/// Manifest contents as TOML data.
|
||||
pub data: toml_edit::Document,
|
||||
pub data: toml_edit::DocumentMut,
|
||||
}
|
||||
|
||||
impl Manifest {
|
||||
|
@ -225,7 +225,7 @@ impl str::FromStr for Manifest {
|
|||
|
||||
/// Read manifest data from string
|
||||
fn from_str(input: &str) -> ::std::result::Result<Self, Self::Err> {
|
||||
let d: toml_edit::Document = input.parse().context("Manifest not valid TOML")?;
|
||||
let d: toml_edit::DocumentMut = input.parse().context("Manifest not valid TOML")?;
|
||||
|
||||
Ok(Manifest { data: d })
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user