Skip to content

Commit

Permalink
refactor(source): Switch PathSource::preload_with to direct construct
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed May 30, 2024
1 parent e1ae47c commit 8339f0a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
3 changes: 1 addition & 2 deletions src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Expand Down
15 changes: 10 additions & 5 deletions src/cargo/sources/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 8339f0a

Please sign in to comment.