Skip to content

Commit 56a5503

Browse files
committed
Auto merge of #7755 - lu-zero:rustc-crate-type, r=alexcrichton
Make cargo-rustc crate-type-aware This fixes #7339 and makes the usage of `cargo rustc` less surprising overall.
2 parents ae08099 + d5eeab8 commit 56a5503

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/cargo/core/workspace.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,33 @@ impl<'cfg> Workspace<'cfg> {
234234
Ok(pkg)
235235
}
236236

237+
pub fn current_mut(&mut self) -> CargoResult<&mut Package> {
238+
let cm = self.current_manifest.clone();
239+
let pkg = self.current_opt_mut().ok_or_else(|| {
240+
anyhow::format_err!(
241+
"manifest path `{}` is a virtual manifest, but this \
242+
command requires running against an actual package in \
243+
this workspace",
244+
cm.display()
245+
)
246+
})?;
247+
Ok(pkg)
248+
}
249+
237250
pub fn current_opt(&self) -> Option<&Package> {
238251
match *self.packages.get(&self.current_manifest) {
239252
MaybePackage::Package(ref p) => Some(p),
240253
MaybePackage::Virtual(..) => None,
241254
}
242255
}
243256

257+
pub fn current_opt_mut(&mut self) -> Option<&mut Package> {
258+
match *self.packages.get_mut(&self.current_manifest) {
259+
MaybePackage::Package(ref mut p) => Some(p),
260+
MaybePackage::Virtual(..) => None,
261+
}
262+
}
263+
244264
pub fn is_virtual(&self) -> bool {
245265
match *self.packages.get(&self.current_manifest) {
246266
MaybePackage::Package(..) => false,
@@ -825,10 +845,18 @@ impl<'cfg> Packages<'cfg> {
825845
self.maybe_get(manifest_path).unwrap()
826846
}
827847

848+
fn get_mut(&mut self, manifest_path: &Path) -> &mut MaybePackage {
849+
self.maybe_get_mut(manifest_path).unwrap()
850+
}
851+
828852
fn maybe_get(&self, manifest_path: &Path) -> Option<&MaybePackage> {
829853
self.packages.get(manifest_path.parent().unwrap())
830854
}
831855

856+
fn maybe_get_mut(&mut self, manifest_path: &Path) -> Option<&mut MaybePackage> {
857+
self.packages.get_mut(manifest_path.parent().unwrap())
858+
}
859+
832860
fn load(&mut self, manifest_path: &Path) -> CargoResult<&MaybePackage> {
833861
let key = manifest_path.parent().unwrap();
834862
match self.packages.entry(key.to_path_buf()) {

0 commit comments

Comments
 (0)