From 8a82df2c213ceb1a7e55aea79914990113ccb5ff Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 27 Mar 2024 15:09:02 -0500 Subject: [PATCH] refactor(toml): Consolidate workspace dependency verification --- src/cargo/util/toml/mod.rs | 39 +++++++++----------------------------- 1 file changed, 9 insertions(+), 30 deletions(-) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index dec86a6293b..ac885bf122c 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -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); @@ -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); } @@ -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"); }