diff --git a/src/cargo/core/source_id.rs b/src/cargo/core/source_id.rs index eec12567f..8c916b7b4 100644 --- a/src/cargo/core/source_id.rs +++ b/src/cargo/core/source_id.rs @@ -204,6 +204,17 @@ impl SourceId { SourceId::new(SourceKind::Path, url, None) } + /// Creates a `SourceId` from a filesystem path. + /// + /// `path`: an absolute path. + pub fn for_manifest_path(manifest_path: &Path) -> CargoResult { + if crate::util::toml::is_embedded(manifest_path) { + Self::for_path(manifest_path) + } else { + Self::for_path(manifest_path.parent().unwrap()) + } + } + /// Creates a `SourceId` from a Git reference. pub fn for_git(url: &Url, reference: GitReference) -> CargoResult { SourceId::new(SourceKind::Git(reference), url.clone(), None) diff --git a/src/cargo/core/workspace.rs b/src/cargo/core/workspace.rs index b988ca668..83662410e 100644 --- a/src/cargo/core/workspace.rs +++ b/src/cargo/core/workspace.rs @@ -1817,11 +1817,7 @@ impl<'gctx> Packages<'gctx> { match self.packages.entry(manifest_path.to_path_buf()) { Entry::Occupied(e) => Ok(e.into_mut()), Entry::Vacant(v) => { - let source_id = if crate::util::toml::is_embedded(manifest_path) { - SourceId::for_path(manifest_path)? - } else { - SourceId::for_path(manifest_path.parent().unwrap())? - }; + let source_id = SourceId::for_manifest_path(manifest_path)?; let manifest = read_manifest(manifest_path, source_id, self.gctx)?; Ok(v.insert(match manifest { EitherManifest::Real(manifest) => {