Skip to content

Commit 2b8c620

Browse files
committed
refactor(source): Switch PathSource::preload_with to direct construct
1 parent 666c199 commit 2b8c620

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/cargo/core/workspace.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,8 +1142,7 @@ impl<'gctx> Workspace<'gctx> {
11421142
MaybePackage::Package(ref p) => p.clone(),
11431143
MaybePackage::Virtual(_) => continue,
11441144
};
1145-
let mut src = PathSource::new(pkg.root(), pkg.package_id().source_id(), self.gctx);
1146-
src.preload_with(pkg);
1145+
let src = PathSource::preload_with(pkg, self.gctx);
11471146
registry.add_preloaded(Box::new(src));
11481147
}
11491148
}

src/cargo/sources/path.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,16 @@ impl<'gctx> PathSource<'gctx> {
5454

5555
/// Preloads a package for this source. The source is assumed that it has
5656
/// yet loaded any other packages.
57-
pub fn preload_with(&mut self, pkg: Package) {
58-
assert!(!self.updated);
59-
assert!(self.packages.is_empty());
60-
self.updated = true;
61-
self.packages.push(pkg);
57+
pub fn preload_with(pkg: Package, gctx: &'gctx GlobalContext) -> Self {
58+
let source_id = pkg.package_id().source_id();
59+
let path = pkg.root().to_owned();
60+
Self {
61+
source_id,
62+
path,
63+
updated: true,
64+
packages: vec![pkg],
65+
gctx,
66+
}
6267
}
6368

6469
/// Gets the package on the root path.

0 commit comments

Comments
 (0)