Skip to content

Commit 954142e

Browse files
committed
refactor(toml): Move path workspace dep validation out of convert_toml
This is part of an effort to remove `convert_toml`
1 parent 37c3080 commit 954142e

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

src/cargo/util/toml/mod.rs

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -175,20 +175,6 @@ fn convert_toml(
175175
source_id: SourceId,
176176
gctx: &GlobalContext,
177177
) -> CargoResult<(EitherManifest, Vec<PathBuf>)> {
178-
if let Some(deps) = manifest
179-
.workspace
180-
.as_ref()
181-
.and_then(|ws| ws.dependencies.as_ref())
182-
{
183-
for (name, dep) in deps {
184-
if dep.is_optional() {
185-
bail!("{name} is optional, but workspace dependencies cannot be optional",);
186-
}
187-
if dep.is_public() {
188-
bail!("{name} is public, but workspace dependencies cannot be public",);
189-
}
190-
}
191-
}
192178
return if manifest.package().is_some() {
193179
let (manifest, paths) = to_real_manifest(manifest, source_id, manifest_file, gctx)?;
194180
Ok((EitherManifest::Real(manifest), paths))
@@ -515,6 +501,21 @@ pub fn to_real_manifest(
515501
);
516502
};
517503

504+
if let Some(deps) = me
505+
.workspace
506+
.as_ref()
507+
.and_then(|ws| ws.dependencies.as_ref())
508+
{
509+
for (name, dep) in deps {
510+
if dep.is_optional() {
511+
bail!("{name} is optional, but workspace dependencies cannot be optional",);
512+
}
513+
if dep.is_public() {
514+
bail!("{name} is public, but workspace dependencies cannot be public",);
515+
}
516+
}
517+
}
518+
518519
let mut nested_paths = vec![];
519520
let mut warnings = vec![];
520521
let mut errors = vec![];
@@ -1282,6 +1283,21 @@ fn to_virtual_manifest(
12821283
) -> CargoResult<(VirtualManifest, Vec<PathBuf>)> {
12831284
let root = manifest_file.parent().unwrap();
12841285

1286+
if let Some(deps) = me
1287+
.workspace
1288+
.as_ref()
1289+
.and_then(|ws| ws.dependencies.as_ref())
1290+
{
1291+
for (name, dep) in deps {
1292+
if dep.is_optional() {
1293+
bail!("{name} is optional, but workspace dependencies cannot be optional",);
1294+
}
1295+
if dep.is_public() {
1296+
bail!("{name} is public, but workspace dependencies cannot be public",);
1297+
}
1298+
}
1299+
}
1300+
12851301
for field in me.requires_package() {
12861302
bail!("this virtual manifest specifies a `{field}` section, which is not allowed");
12871303
}

0 commit comments

Comments
 (0)