From 512ce788c510a1c510c9f7b27510af71cb37c174 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Sat, 18 Nov 2023 21:33:27 -0600 Subject: [PATCH 1/2] fix(toml): Prevent workspace=false in API --- src/cargo/util/toml/schema.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/cargo/util/toml/schema.rs b/src/cargo/util/toml/schema.rs index 883fbb2dc42..a8e760c8c98 100644 --- a/src/cargo/util/toml/schema.rs +++ b/src/cargo/util/toml/schema.rs @@ -411,7 +411,19 @@ impl<'de> de::Deserialize<'de> for InheritableBtreeMap { #[serde(rename_all = "kebab-case")] pub struct TomlInheritedField { #[serde(deserialize_with = "bool_no_false")] - pub workspace: bool, + workspace: bool, +} + +impl TomlInheritedField { + pub fn new() -> Self { + TomlInheritedField { workspace: true } + } +} + +impl Default for TomlInheritedField { + fn default() -> Self { + Self::new() + } } fn bool_no_false<'de, D: de::Deserializer<'de>>(deserializer: D) -> Result { From 7e4d0a6149c8a6bb30b2201021883e67adb85c68 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Sat, 18 Nov 2023 21:48:35 -0600 Subject: [PATCH 2/2] refactor(toml): Move accessor to be part of schema API --- src/cargo/util/toml/mod.rs | 7 ------- src/cargo/util/toml/schema.rs | 9 +++++++++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index c07aef05990..3352a697160 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -1568,13 +1568,6 @@ impl schema::InheritableField { }), } } - - fn as_value(&self) -> Option<&T> { - match self { - schema::InheritableField::Inherit(_) => None, - schema::InheritableField::Value(defined) => Some(defined), - } - } } impl schema::InheritableDependency { diff --git a/src/cargo/util/toml/schema.rs b/src/cargo/util/toml/schema.rs index a8e760c8c98..96114606c9c 100644 --- a/src/cargo/util/toml/schema.rs +++ b/src/cargo/util/toml/schema.rs @@ -170,6 +170,15 @@ pub enum InheritableField { Inherit(TomlInheritedField), } +impl InheritableField { + pub fn as_value(&self) -> Option<&T> { + match self { + InheritableField::Inherit(_) => None, + InheritableField::Value(defined) => Some(defined), + } + } +} + //. This already has a `Deserialize` impl from version_trim_whitespace pub type InheritableSemverVersion = InheritableField; impl<'de> de::Deserialize<'de> for InheritableSemverVersion {