Skip to content

Commit

Permalink
refactor(toml): Flatten convert_toml
Browse files Browse the repository at this point in the history
This is to work towards tracking everything needed for diagnostics in
`Manifest`
  • Loading branch information
epage committed Mar 15, 2024
1 parent dd56d79 commit 4ed67e3
Showing 1 changed file with 8 additions and 25 deletions.
33 changes: 8 additions & 25 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,14 @@ pub fn read_manifest(
let toml = deserialize_toml(&document)
.map_err(|e| emit_diagnostic(e.into(), &contents, path, gctx))?;

convert_toml(toml, path, source_id, gctx).map_err(|err| {
(|| {
if toml.package().is_some() {
to_real_manifest(toml, source_id, path, gctx).map(EitherManifest::Real)
} else {
to_virtual_manifest(toml, source_id, path, gctx).map(EitherManifest::Virtual)
}
})()
.map_err(|err| {
ManifestError::new(
err.context(format!("failed to parse manifest at `{}`", path.display())),
path.into(),
Expand Down Expand Up @@ -160,30 +167,6 @@ fn emit_diagnostic(
return AlreadyPrintedError::new(e.into()).into();
}

/// Parse an already-loaded `Cargo.toml` as a Cargo manifest.
///
/// This could result in a real or virtual manifest being returned.
///
/// A list of nested paths is also returned, one for each path dependency
/// within the manifest. For virtual manifests, these paths can only
/// come from patched or replaced dependencies. These paths are not
/// canonicalized.
#[tracing::instrument(skip_all)]
fn convert_toml(
manifest: manifest::TomlManifest,
manifest_file: &Path,
source_id: SourceId,
gctx: &GlobalContext,
) -> CargoResult<EitherManifest> {
return if manifest.package().is_some() {
let manifest = to_real_manifest(manifest, source_id, manifest_file, gctx)?;
Ok(EitherManifest::Real(manifest))
} else {
let manifest = to_virtual_manifest(manifest, source_id, manifest_file, gctx)?;
Ok(EitherManifest::Virtual(manifest))
};
}

fn stringify(dst: &mut String, path: &serde_ignored::Path<'_>) {
use serde_ignored::Path;

Expand Down

0 comments on commit 4ed67e3

Please sign in to comment.