Skip to content

Commit 463f307

Browse files
committed
Auto merge of #13021 - epage:inherit, r=weihanglo
refactor(toml): Better abstract inheritance details There is no reason that the caller for inheriting needs to know the details of the inner types doing inheritance.
2 parents 65d0eb5 + 7bd5aa3 commit 463f307

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/cargo/util/toml/mod.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -661,9 +661,7 @@ impl schema::TomlManifest {
661661

662662
let mut deps: BTreeMap<String, schema::InheritableDependency> = BTreeMap::new();
663663
for (n, v) in dependencies.iter() {
664-
let resolved = v
665-
.clone()
666-
.inherit_with(n, |dep| dep.inherit_with(n, inheritable, cx))?;
664+
let resolved = v.clone().inherit_with(n, inheritable, cx)?;
667665
let dep = resolved.to_dependency(n, cx, kind)?;
668666
let name_in_toml = dep.name_in_toml().as_str();
669667
validate_package_name(name_in_toml, "dependency name", "")?;
@@ -1573,15 +1571,16 @@ impl<T> schema::InheritableField<T> {
15731571
impl schema::InheritableDependency {
15741572
fn inherit_with<'a>(
15751573
self,
1576-
label: &str,
1577-
get_ws_inheritable: impl FnOnce(&schema::TomlInheritedDependency) -> CargoResult<TomlDependency>,
1574+
name: &str,
1575+
inheritable: impl FnOnce() -> CargoResult<&'a InheritableFields>,
1576+
cx: &mut Context<'_, '_>,
15781577
) -> CargoResult<TomlDependency> {
15791578
match self {
15801579
schema::InheritableDependency::Value(value) => Ok(value),
15811580
schema::InheritableDependency::Inherit(w) => {
1582-
get_ws_inheritable(&w).with_context(|| {
1581+
w.inherit_with(name, inheritable, cx).with_context(|| {
15831582
format!(
1584-
"error inheriting `{label}` from workspace root manifest's `workspace.dependencies.{label}`",
1583+
"error inheriting `{name}` from workspace root manifest's `workspace.dependencies.{name}`",
15851584
)
15861585
})
15871586
}

0 commit comments

Comments
 (0)