Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(toml): Better abstract inheritance details #13021

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,9 +661,7 @@ impl schema::TomlManifest {

let mut deps: BTreeMap<String, schema::InheritableDependency> = BTreeMap::new();
for (n, v) in dependencies.iter() {
let resolved = v
.clone()
.inherit_with(n, |dep| dep.inherit_with(n, inheritable, cx))?;
let resolved = v.clone().inherit_with(n, inheritable, cx)?;
let dep = resolved.to_dependency(n, cx, kind)?;
let name_in_toml = dep.name_in_toml().as_str();
validate_package_name(name_in_toml, "dependency name", "")?;
Expand Down Expand Up @@ -1573,15 +1571,16 @@ impl<T> schema::InheritableField<T> {
impl schema::InheritableDependency {
fn inherit_with<'a>(
self,
label: &str,
get_ws_inheritable: impl FnOnce(&schema::TomlInheritedDependency) -> CargoResult<TomlDependency>,
name: &str,
inheritable: impl FnOnce() -> CargoResult<&'a InheritableFields>,
cx: &mut Context<'_, '_>,
) -> CargoResult<TomlDependency> {
match self {
schema::InheritableDependency::Value(value) => Ok(value),
schema::InheritableDependency::Inherit(w) => {
get_ws_inheritable(&w).with_context(|| {
w.inherit_with(name, inheritable, cx).with_context(|| {
format!(
"error inheriting `{label}` from workspace root manifest's `workspace.dependencies.{label}`",
"error inheriting `{name}` from workspace root manifest's `workspace.dependencies.{name}`",
)
})
}
Expand Down