Skip to content

Commit

Permalink
Auto merge of #7755 - lu-zero:rustc-crate-type, r=alexcrichton
Browse files Browse the repository at this point in the history
Make cargo-rustc crate-type-aware

This fixes #7339 and makes the usage of `cargo rustc` less surprising overall.
  • Loading branch information
bors committed Jan 13, 2020
2 parents ae08099 + d5eeab8 commit 56a5503
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,33 @@ impl<'cfg> Workspace<'cfg> {
Ok(pkg)
}

pub fn current_mut(&mut self) -> CargoResult<&mut Package> {
let cm = self.current_manifest.clone();
let pkg = self.current_opt_mut().ok_or_else(|| {
anyhow::format_err!(
"manifest path `{}` is a virtual manifest, but this \
command requires running against an actual package in \
this workspace",
cm.display()
)
})?;
Ok(pkg)
}

pub fn current_opt(&self) -> Option<&Package> {
match *self.packages.get(&self.current_manifest) {
MaybePackage::Package(ref p) => Some(p),
MaybePackage::Virtual(..) => None,
}
}

pub fn current_opt_mut(&mut self) -> Option<&mut Package> {
match *self.packages.get_mut(&self.current_manifest) {
MaybePackage::Package(ref mut p) => Some(p),
MaybePackage::Virtual(..) => None,
}
}

pub fn is_virtual(&self) -> bool {
match *self.packages.get(&self.current_manifest) {
MaybePackage::Package(..) => false,
Expand Down Expand Up @@ -825,10 +845,18 @@ impl<'cfg> Packages<'cfg> {
self.maybe_get(manifest_path).unwrap()
}

fn get_mut(&mut self, manifest_path: &Path) -> &mut MaybePackage {
self.maybe_get_mut(manifest_path).unwrap()
}

fn maybe_get(&self, manifest_path: &Path) -> Option<&MaybePackage> {
self.packages.get(manifest_path.parent().unwrap())
}

fn maybe_get_mut(&mut self, manifest_path: &Path) -> Option<&mut MaybePackage> {
self.packages.get_mut(manifest_path.parent().unwrap())
}

fn load(&mut self, manifest_path: &Path) -> CargoResult<&MaybePackage> {
let key = manifest_path.parent().unwrap();
match self.packages.entry(key.to_path_buf()) {
Expand Down

0 comments on commit 56a5503

Please sign in to comment.