Skip to content

Commit

Permalink
refactor(toml): Move path workspace dep validation out of convert_toml
Browse files Browse the repository at this point in the history
This is part of an effort to remove `convert_toml`
  • Loading branch information
epage committed Mar 15, 2024
1 parent 3b91f57 commit de0c136
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,20 +175,6 @@ fn convert_toml(
source_id: SourceId,
gctx: &GlobalContext,
) -> CargoResult<(EitherManifest, Vec<PathBuf>)> {
if let Some(deps) = manifest
.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",);
}
}
}
return if manifest.package().is_some() {
let (manifest, paths) = to_real_manifest(manifest, source_id, manifest_file, gctx)?;
Ok((EitherManifest::Real(manifest), paths))
Expand Down Expand Up @@ -515,6 +501,21 @@ pub fn to_real_manifest(
);
};

if let Some(deps) = me
.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",);
}
}
}

let mut nested_paths = vec![];
let mut warnings = vec![];
let mut errors = vec![];
Expand Down Expand Up @@ -1282,6 +1283,21 @@ fn to_virtual_manifest(
) -> CargoResult<(VirtualManifest, Vec<PathBuf>)> {
let root = manifest_file.parent().unwrap();

if let Some(deps) = me
.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 me.requires_package() {
bail!("this virtual manifest specifies a `{field}` section, which is not allowed");
}
Expand Down

0 comments on commit de0c136

Please sign in to comment.