Skip to content

Commit

Permalink
refactor(toml): Consolidate workspace dependency verification
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Mar 27, 2024
1 parent 453f39f commit 8a82df2
Showing 1 changed file with 9 additions and 30 deletions.
39 changes: 9 additions & 30 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,21 +479,6 @@ pub fn to_real_manifest(
);
};

if let Some(deps) = original_toml
.workspace
.as_ref()
.and_then(|ws| ws.dependencies.as_ref())
{
for (name, dep) in deps {
if dep.is_optional() {
bail!("{name} is optional, but workspace dependencies cannot be optional",);
}
if dep.is_public() {
bail!("{name} is public, but workspace dependencies cannot be public",);
}
}
}

// Parse features first so they will be available when parsing other parts of the TOML.
let empty = Vec::new();
let cargo_features = original_toml.cargo_features.as_ref().unwrap_or(&empty);
Expand Down Expand Up @@ -1225,6 +1210,15 @@ fn to_workspace_config(
(Some(toml_config), None) => {
verify_lints(toml_config.lints.as_ref(), gctx, warnings)?;
if let Some(ws_deps) = &toml_config.dependencies {
for (name, dep) in ws_deps {
if dep.is_optional() {
bail!("{name} is optional, but workspace dependencies cannot be optional",);
}
if dep.is_public() {
bail!("{name} is public, but workspace dependencies cannot be public",);
}
}

for (name, dep) in ws_deps {
unused_dep_keys(name, "workspace.dependencies", dep.unused_keys(), warnings);
}
Expand Down Expand Up @@ -1278,21 +1272,6 @@ fn to_virtual_manifest(

let mut resolved_toml = original_toml.clone();

if let Some(deps) = original_toml
.workspace
.as_ref()
.and_then(|ws| ws.dependencies.as_ref())
{
for (name, dep) in deps {
if dep.is_optional() {
bail!("{name} is optional, but workspace dependencies cannot be optional",);
}
if dep.is_public() {
bail!("{name} is public, but workspace dependencies cannot be public",);
}
}
}

for field in original_toml.requires_package() {
bail!("this virtual manifest specifies a `{field}` section, which is not allowed");
}
Expand Down

0 comments on commit 8a82df2

Please sign in to comment.