Skip to content

Commit f8a63f6

Browse files
committed
refactor(toml): Hard-code InheritableField for package table
1 parent 58b0b18 commit f8a63f6

File tree

2 files changed

+12
-32
lines changed

2 files changed

+12
-32
lines changed

src/cargo/util/toml/mod.rs

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,30 +1539,17 @@ impl schema::TomlPackage {
15391539
}
15401540
}
15411541

1542-
/// This Trait exists to make [`schema::InheritableField::Inherit`] generic. It makes deserialization of
1543-
/// [`schema::InheritableField`] much easier, as well as making error messages for
1544-
/// [`schema::InheritableField::resolve`] much nicer
1545-
///
1546-
/// Implementors should have a field `workspace` with the type of `bool`. It is used to ensure
1547-
/// `workspace` is not `false` in a `Cargo.toml`
1548-
pub trait WorkspaceInherit {
1549-
/// This is the workspace table that is being inherited from.
1550-
/// For example `[workspace.dependencies]` would be the table "dependencies"
1551-
fn inherit_toml_table(&self) -> &str;
1552-
}
1553-
1554-
impl<T, W: WorkspaceInherit> schema::InheritableField<T, W> {
1542+
impl<T> schema::InheritableField<T> {
15551543
fn resolve<'a>(
15561544
self,
15571545
label: &str,
15581546
get_ws_inheritable: impl FnOnce() -> CargoResult<T>,
15591547
) -> CargoResult<T> {
15601548
match self {
15611549
schema::InheritableField::Value(value) => Ok(value),
1562-
schema::InheritableField::Inherit(w) => get_ws_inheritable().with_context(|| {
1550+
schema::InheritableField::Inherit(_) => get_ws_inheritable().with_context(|| {
15631551
format!(
1564-
"error inheriting `{label}` from workspace root manifest's `workspace.{}.{label}`",
1565-
w.inherit_toml_table(),
1552+
"error inheriting `{label}` from workspace root manifest's `workspace.package.{label}`",
15661553
)
15671554
}),
15681555
}
@@ -1576,12 +1563,6 @@ impl<T, W: WorkspaceInherit> schema::InheritableField<T, W> {
15761563
}
15771564
}
15781565

1579-
impl WorkspaceInherit for schema::TomlInheritedField {
1580-
fn inherit_toml_table(&self) -> &str {
1581-
"package"
1582-
}
1583-
}
1584-
15851566
impl schema::InheritableDependency {
15861567
fn resolve_with_self<'a>(
15871568
self,

src/cargo/util/toml/schema.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,15 @@ pub struct TomlPackage {
174174
/// An enum that allows for inheriting keys from a workspace in a Cargo.toml.
175175
#[derive(Serialize, Copy, Clone, Debug)]
176176
#[serde(untagged)]
177-
pub enum InheritableField<T, W> {
177+
pub enum InheritableField<T> {
178178
/// The type that that is used when not inheriting from a workspace.
179179
Value(T),
180180
/// The type when inheriting from a workspace.
181-
Inherit(W),
181+
Inherit(TomlInheritedField),
182182
}
183183

184184
//. This already has a `Deserialize` impl from version_trim_whitespace
185-
pub type InheritableSemverVersion = InheritableField<semver::Version, TomlInheritedField>;
185+
pub type InheritableSemverVersion = InheritableField<semver::Version>;
186186
impl<'de> de::Deserialize<'de> for InheritableSemverVersion {
187187
fn deserialize<D>(d: D) -> Result<Self, D::Error>
188188
where
@@ -201,7 +201,7 @@ impl<'de> de::Deserialize<'de> for InheritableSemverVersion {
201201
}
202202
}
203203

204-
pub type InheritableString = InheritableField<String, TomlInheritedField>;
204+
pub type InheritableString = InheritableField<String>;
205205
impl<'de> de::Deserialize<'de> for InheritableString {
206206
fn deserialize<D>(d: D) -> Result<Self, D::Error>
207207
where
@@ -236,7 +236,7 @@ impl<'de> de::Deserialize<'de> for InheritableString {
236236
}
237237
}
238238

239-
pub type InheritableRustVersion = InheritableField<RustVersion, TomlInheritedField>;
239+
pub type InheritableRustVersion = InheritableField<RustVersion>;
240240
impl<'de> de::Deserialize<'de> for InheritableRustVersion {
241241
fn deserialize<D>(d: D) -> Result<Self, D::Error>
242242
where
@@ -272,7 +272,7 @@ impl<'de> de::Deserialize<'de> for InheritableRustVersion {
272272
}
273273
}
274274

275-
pub type InheritableVecString = InheritableField<Vec<String>, TomlInheritedField>;
275+
pub type InheritableVecString = InheritableField<Vec<String>>;
276276
impl<'de> de::Deserialize<'de> for InheritableVecString {
277277
fn deserialize<D>(d: D) -> Result<Self, D::Error>
278278
where
@@ -307,7 +307,7 @@ impl<'de> de::Deserialize<'de> for InheritableVecString {
307307
}
308308
}
309309

310-
pub type InheritableStringOrBool = InheritableField<StringOrBool, TomlInheritedField>;
310+
pub type InheritableStringOrBool = InheritableField<StringOrBool>;
311311
impl<'de> de::Deserialize<'de> for InheritableStringOrBool {
312312
fn deserialize<D>(d: D) -> Result<Self, D::Error>
313313
where
@@ -351,7 +351,7 @@ impl<'de> de::Deserialize<'de> for InheritableStringOrBool {
351351
}
352352
}
353353

354-
pub type InheritableVecStringOrBool = InheritableField<VecStringOrBool, TomlInheritedField>;
354+
pub type InheritableVecStringOrBool = InheritableField<VecStringOrBool>;
355355
impl<'de> de::Deserialize<'de> for InheritableVecStringOrBool {
356356
fn deserialize<D>(d: D) -> Result<Self, D::Error>
357357
where
@@ -395,8 +395,7 @@ impl<'de> de::Deserialize<'de> for InheritableVecStringOrBool {
395395
}
396396
}
397397

398-
pub type InheritableBtreeMap =
399-
InheritableField<BTreeMap<String, BTreeMap<String, String>>, TomlInheritedField>;
398+
pub type InheritableBtreeMap = InheritableField<BTreeMap<String, BTreeMap<String, String>>>;
400399

401400
impl<'de> de::Deserialize<'de> for InheritableBtreeMap {
402401
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>

0 commit comments

Comments
 (0)