diff --git a/src/cargo/ops/common_for_install_and_uninstall.rs b/src/cargo/ops/common_for_install_and_uninstall.rs index 78e53af5c4f..9f0c5dd206e 100644 --- a/src/cargo/ops/common_for_install_and_uninstall.rs +++ b/src/cargo/ops/common_for_install_and_uninstall.rs @@ -544,12 +544,29 @@ where let pkg = Box::new(source).download_now(pkgid, config)?; Ok(pkg) } - None => bail!( - "could not find `{}` in {} with version `{}`", - dep.package_name(), - source.source_id(), - dep.version_req(), - ), + None => { + let is_yanked: bool = if dep.version_req().is_exact() { + let version: String = dep.version_req().to_string(); + PackageId::new(dep.package_name(), &version[1..], source.source_id()) + .map_or(false, |pkg_id| source.is_yanked(pkg_id).unwrap_or(false)) + } else { + false + }; + if is_yanked { + bail!( + "cannot install package `{}`, it has been yanked from {}", + dep.package_name(), + source.source_id() + ) + } else { + bail!( + "could not find `{}` in {} with version `{}`", + dep.package_name(), + source.source_id(), + dep.version_req(), + ) + } + } } } diff --git a/tests/testsuite/install.rs b/tests/testsuite/install.rs index 9c5a1e72651..d5fe04194a6 100644 --- a/tests/testsuite/install.rs +++ b/tests/testsuite/install.rs @@ -5,15 +5,16 @@ use std::io::prelude::*; use cargo_test_support::cross_compile; use cargo_test_support::git; -use cargo_test_support::install::{ - assert_has_installed_exe, assert_has_not_installed_exe, cargo_home, -}; -use cargo_test_support::paths; use cargo_test_support::registry::{registry_path, registry_url, Package}; use cargo_test_support::{ basic_manifest, cargo_process, no_such_file_err_msg, project, symlink_supported, t, }; +use cargo_test_support::install::{ + assert_has_installed_exe, assert_has_not_installed_exe, cargo_home, +}; +use cargo_test_support::paths; + fn pkg(name: &str, vers: &str) { Package::new(name, vers) .file("src/lib.rs", "") @@ -1555,3 +1556,15 @@ fn install_git_with_symlink_home() { ) .run(); } + +#[cargo_test] +fn install_yanked_cargo_package() { + Package::new("baz", "0.0.1").yanked(true).publish(); + cargo_process("install baz --version 0.0.1") + .with_status(101) + .with_stderr_contains( + "error: cannot install package `baz`, it has been yanked from registry \ + `https://github.com/rust-lang/crates.io-index`", + ) + .run(); +} diff --git a/tests/testsuite/install_upgrade.rs b/tests/testsuite/install_upgrade.rs index 41f00087126..6de8277d62b 100644 --- a/tests/testsuite/install_upgrade.rs +++ b/tests/testsuite/install_upgrade.rs @@ -799,11 +799,9 @@ fn already_installed_updates_yank_status_on_upgrade() { cargo_process("install foo --version=1.0.1") .with_status(101) - .with_stderr( - "\ -[UPDATING] `[..]` index -[ERROR] could not find `foo` in registry `[..]` with version `=1.0.1` -", + .with_stderr_contains( + "error: cannot install package `foo`, it has been yanked from registry \ + `https://github.com/rust-lang/crates.io-index`", ) .run();