Skip to content

Commit 226eefd

Browse files
committed
add the -Zallow-yanked-deps unstable CLI flag
1 parent 78bae45 commit 226eefd

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

src/cargo/core/features.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ pub struct CliUnstable {
318318
pub advanced_env: bool,
319319
pub config_profile: bool,
320320
pub compile_progress: bool,
321+
pub allow_yanked_deps: bool,
321322
}
322323

323324
impl CliUnstable {
@@ -355,6 +356,7 @@ impl CliUnstable {
355356
"advanced-env" => self.advanced_env = true,
356357
"config-profile" => self.config_profile = true,
357358
"compile-progress" => self.compile_progress = true,
359+
"allow-yanked-deps" => self.allow_yanked_deps = true,
358360
_ => bail!("unknown `-Z` flag specified: {}", k),
359361
}
360362

src/cargo/sources/registry/index.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,15 @@ impl<'cfg> RegistryIndex<'cfg> {
268268
load: &mut RegistryData,
269269
f: &mut FnMut(Summary),
270270
) -> CargoResult<()> {
271+
let allow_yanked_deps = self.config.cli_unstable().allow_yanked_deps;
271272
let source_id = self.source_id.clone();
272273
let name = dep.package_name().as_str();
273274
let summaries = self.summaries(name, load)?;
274275
let summaries = summaries
275276
.iter()
276-
.filter(|&&(_, yanked)| dep.source_id().precise().is_some() || !yanked)
277+
.filter(|&&(_, yanked)| {
278+
dep.source_id().precise().is_some() || allow_yanked_deps || !yanked
279+
})
277280
.map(|s| s.0.clone());
278281

279282
// Handle `cargo update --precise` here. If specified, our own source

tests/testsuite/registry.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,42 @@ required by package `bar v0.0.1`
523523
).run();
524524
}
525525

526+
#[test]
527+
fn yanks_are_used_with_z_flag() {
528+
let p = project()
529+
.file(
530+
"Cargo.toml",
531+
r#"
532+
[project]
533+
name = "foo"
534+
version = "0.0.1"
535+
authors = []
536+
537+
[dependencies]
538+
bar = "*"
539+
"#,
540+
).file("src/main.rs", "fn main() {}")
541+
.build();
542+
543+
Package::new("baz", "0.0.1").publish();
544+
Package::new("baz", "0.0.2").yanked(true).publish();
545+
Package::new("bar", "0.0.1").dep("baz", "=0.0.2").publish();
546+
547+
p.cargo("build -Zallow-yanked-deps")
548+
.masquerade_as_nightly_cargo()
549+
.with_stderr(&format!(
550+
"\
551+
[UPDATING] registry `[..]`
552+
[DOWNLOADING] [..] (registry `file://[..]`)
553+
[DOWNLOADING] [..] (registry `file://[..]`)
554+
[COMPILING] baz v0.0.2
555+
[COMPILING] bar v0.0.1
556+
[COMPILING] foo v0.0.1 (CWD)
557+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
558+
",
559+
)).run();
560+
}
561+
526562
#[test]
527563
fn yanks_in_lockfiles_are_ok() {
528564
let p = project()

0 commit comments

Comments
 (0)