diff --git a/src/cargo/core/workspace.rs b/src/cargo/core/workspace.rs index 015bee2341f..1dc75c881e4 100644 --- a/src/cargo/core/workspace.rs +++ b/src/cargo/core/workspace.rs @@ -1142,8 +1142,7 @@ impl<'gctx> Workspace<'gctx> { MaybePackage::Package(ref p) => p.clone(), MaybePackage::Virtual(_) => continue, }; - let mut src = PathSource::new(pkg.root(), pkg.package_id().source_id(), self.gctx); - src.preload_with(pkg); + let src = PathSource::preload_with(pkg, self.gctx); registry.add_preloaded(Box::new(src)); } } diff --git a/src/cargo/sources/path.rs b/src/cargo/sources/path.rs index 46a29d773a9..6c05cb20fed 100644 --- a/src/cargo/sources/path.rs +++ b/src/cargo/sources/path.rs @@ -54,11 +54,16 @@ impl<'gctx> PathSource<'gctx> { /// Preloads a package for this source. The source is assumed that it has /// yet loaded any other packages. - pub fn preload_with(&mut self, pkg: Package) { - assert!(!self.updated); - assert!(self.packages.is_empty()); - self.updated = true; - self.packages.push(pkg); + pub fn preload_with(pkg: Package, gctx: &'gctx GlobalContext) -> Self { + let source_id = pkg.package_id().source_id(); + let path = pkg.root().to_owned(); + Self { + source_id, + path, + updated: true, + packages: vec![pkg], + gctx, + } } /// Gets the package on the root path.