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

fix(toml): Warn on unused workspace.dependencies keys on virtual workspaces #13664

Merged
merged 12 commits into from
Mar 28, 2024
Merged
13 changes: 6 additions & 7 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1151,10 +1151,8 @@ fn resolve_and_validate_dependencies(

let mut deps: BTreeMap<manifest::PackageName, manifest::InheritableDependency> =
BTreeMap::new();
for (n, v) in dependencies.iter() {
let resolved = dependency_inherit_with(v.clone(), n, inheritable, manifest_ctx)?;
let dep = dep_to_dependency(&resolved, n, manifest_ctx, kind)?;
let name_in_toml = dep.name_in_toml().as_str();
for (name_in_toml, v) in dependencies.iter() {
let resolved = dependency_inherit_with(v.clone(), name_in_toml, inheritable, manifest_ctx)?;
let kind_name = match kind {
Some(k) => k.kind_table(),
None => "dependencies",
Expand All @@ -1173,7 +1171,7 @@ fn resolve_and_validate_dependencies(
let mut resolved = resolved;
if let manifest::TomlDependency::Detailed(ref mut d) = resolved {
if d.public.is_some() {
if matches!(dep.kind(), DepKind::Normal) {
if matches!(kind, None) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: matches! against an Option looks pretty not idiomatic to me

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW it seems like non of the usage of resolve_and_validate_dependencies receives a DepKind::Normal. I wonder if we could remove the Option.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a high churn area in a follow up PR, can we defer this?

if !manifest_ctx
.features
.require(Feature::public_dependency())
Expand All @@ -1182,7 +1180,7 @@ fn resolve_and_validate_dependencies(
{
d.public = None;
manifest_ctx.warnings.push(format!(
"ignoring `public` on dependency {name}, pass `-Zpublic-dependency` to enable support for it", name = &dep.name_in_toml()
"ignoring `public` on dependency {name_in_toml}, pass `-Zpublic-dependency` to enable support for it"
))
}
} else {
Expand All @@ -1191,9 +1189,10 @@ fn resolve_and_validate_dependencies(
}
}

let dep = dep_to_dependency(&resolved, name_in_toml, manifest_ctx, kind)?;
manifest_ctx.deps.push(dep);
deps.insert(
n.clone(),
name_in_toml.clone(),
manifest::InheritableDependency::Value(resolved.clone()),
);
}
Expand Down