From f2a6514a0985fd34fdb4e9538370592d3bdcfe97 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 31 Oct 2023 11:57:53 -0500 Subject: [PATCH 1/6] refactor(toml): Clairfy unued_keys field --- src/cargo/util/toml/mod.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index a9881497d8d..9d643f5b947 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -2064,7 +2064,7 @@ impl MaybeWorkspaceDependency { fn unused_keys(&self) -> Vec { match self { MaybeWorkspaceDependency::Defined(d) => d.unused_keys(), - MaybeWorkspaceDependency::Workspace(w) => w.other.keys().cloned().collect(), + MaybeWorkspaceDependency::Workspace(w) => w.unused_keys.keys().cloned().collect(), } } } @@ -2104,7 +2104,7 @@ pub struct TomlWorkspaceDependency { /// This is here to provide a way to see the "unused manifest keys" when deserializing #[serde(skip_serializing)] #[serde(flatten)] - other: BTreeMap, + unused_keys: BTreeMap, } impl TomlWorkspaceDependency { @@ -2212,7 +2212,7 @@ impl TomlDependency { fn unused_keys(&self) -> Vec { match self { TomlDependency::Simple(_) => vec![], - TomlDependency::Detailed(detailed) => detailed.other.keys().cloned().collect(), + TomlDependency::Detailed(detailed) => detailed.unused_keys.keys().cloned().collect(), } } } @@ -2329,7 +2329,7 @@ pub struct DetailedTomlDependency { /// This is here to provide a way to see the "unused manifest keys" when deserializing #[serde(skip_serializing)] #[serde(flatten)] - other: BTreeMap, + unused_keys: BTreeMap, } impl DetailedTomlDependency { @@ -2635,7 +2635,7 @@ impl Default for DetailedTomlDependency

{ artifact: Default::default(), lib: Default::default(), target: Default::default(), - other: Default::default(), + unused_keys: Default::default(), } } } From d3bff4ee229e600c898b1bfb80e71959db7cac0a Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 31 Oct 2023 12:00:35 -0500 Subject: [PATCH 2/6] refactor(toml): Re-arrange tables due to toml upgrade In switching from toml v0.5 to toml_edit, we no longer need to have tables after all fields. --- src/cargo/util/toml/mod.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 9d643f5b947..b074c730a3b 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -1536,15 +1536,12 @@ pub struct TomlWorkspace { default_members: Option>, exclude: Option>, resolver: Option, + metadata: Option, // Properties that can be inherited by members. package: Option, dependencies: Option>, lints: Option, - - // Note that this field must come last due to the way toml serialization - // works which requires tables to be emitted after all values. - metadata: Option, } /// A group of fields that are inheritable by members of the workspace @@ -1710,13 +1707,11 @@ pub struct TomlPackage { repository: Option, resolver: Option, + metadata: Option, + // Provide a helpful error message for a common user error. #[serde(rename = "cargo-features", skip_serializing)] _invalid_cargo_features: Option, - - // Note that this field must come last due to the way toml serialization - // works which requires tables to be emitted after all values. - metadata: Option, } impl TomlPackage { From 26905f2dc39f4de2a43cb9bf1f1e8ab41368e06b Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 31 Oct 2023 12:02:39 -0500 Subject: [PATCH 3/6] docs(toml): Promote a comment to doc-comment --- src/cargo/util/toml/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index b074c730a3b..e3964dbcb14 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -1709,7 +1709,7 @@ pub struct TomlPackage { metadata: Option, - // Provide a helpful error message for a common user error. + /// Provide a helpful error message for a common user error. #[serde(rename = "cargo-features", skip_serializing)] _invalid_cargo_features: Option, } From 7b7fa1a0ed365ff5e741a56cb5ad7fb900e130b8 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 31 Oct 2023 12:05:35 -0500 Subject: [PATCH 4/6] refactor(toml): Separate unused_keys from payload --- src/cargo/util/toml/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index e3964dbcb14..e3bdf9ed35f 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -2096,6 +2096,7 @@ pub struct TomlWorkspaceDependency { default_features2: Option, optional: Option, public: Option, + /// This is here to provide a way to see the "unused manifest keys" when deserializing #[serde(skip_serializing)] #[serde(flatten)] @@ -2321,6 +2322,7 @@ pub struct DetailedTomlDependency { lib: Option, /// A platform name, like `x86_64-apple-darwin` target: Option, + /// This is here to provide a way to see the "unused manifest keys" when deserializing #[serde(skip_serializing)] #[serde(flatten)] From 62fde423482e59a4780e813215aea121f7763135 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 31 Oct 2023 12:06:11 -0500 Subject: [PATCH 5/6] refactor(toml): Group members and excludes --- src/cargo/util/toml/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index e3bdf9ed35f..69e014a6adb 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -1532,9 +1532,9 @@ fn unique_build_targets( #[derive(Debug, Deserialize, Serialize, Clone)] pub struct TomlWorkspace { members: Option>, + exclude: Option>, #[serde(rename = "default-members")] default_members: Option>, - exclude: Option>, resolver: Option, metadata: Option, From f42b16184788c86dd2e24decc79ae3c92dd2b01b Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 31 Oct 2023 12:14:23 -0500 Subject: [PATCH 6/6] refactor(toml): Consistently apply rename_all --- src/cargo/util/toml/mod.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 69e014a6adb..f6d6c5ea5e1 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -1530,10 +1530,10 @@ fn unique_build_targets( } #[derive(Debug, Deserialize, Serialize, Clone)] +#[serde(rename_all = "kebab-case")] pub struct TomlWorkspace { members: Option>, exclude: Option>, - #[serde(rename = "default-members")] default_members: Option>, resolver: Option, metadata: Option, @@ -1546,6 +1546,7 @@ pub struct TomlWorkspace { /// A group of fields that are inheritable by members of the workspace #[derive(Clone, Debug, Default, Deserialize, Serialize)] +#[serde(rename_all = "kebab-case")] pub struct InheritableFields { // We use skip here since it will never be present when deserializing // and we don't want it present when serializing @@ -1563,7 +1564,6 @@ pub struct InheritableFields { keywords: Option>, categories: Option>, license: Option, - #[serde(rename = "license-file")] license_file: Option, repository: Option, publish: Option, @@ -1571,7 +1571,6 @@ pub struct InheritableFields { badges: Option>>, exclude: Option>, include: Option>, - #[serde(rename = "rust-version")] rust_version: Option, // We use skip here since it will never be present when deserializing // and we don't want it present when serializing @@ -2029,6 +2028,7 @@ impl<'de> de::Deserialize<'de> for MaybeWorkspaceBtreeMap { } #[derive(Deserialize, Serialize, Copy, Clone, Debug)] +#[serde(rename_all = "kebab-case")] pub struct TomlWorkspaceField { #[serde(deserialize_with = "bool_no_false")] workspace: bool, @@ -3380,13 +3380,12 @@ impl TomlTarget { /// Corresponds to a `target` entry, but `TomlTarget` is already used. #[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(rename_all = "kebab-case")] struct TomlPlatform { dependencies: Option>, - #[serde(rename = "build-dependencies")] build_dependencies: Option>, #[serde(rename = "build_dependencies")] build_dependencies2: Option>, - #[serde(rename = "dev-dependencies")] dev_dependencies: Option>, #[serde(rename = "dev_dependencies")] dev_dependencies2: Option>, @@ -3394,6 +3393,7 @@ struct TomlPlatform { #[derive(Deserialize, Serialize, Debug, Clone)] #[serde(expecting = "a lints table")] +#[serde(rename_all = "kebab-case")] pub struct MaybeWorkspaceLints { #[serde(skip_serializing_if = "is_false")] #[serde(deserialize_with = "bool_no_false", default)]