diff --git a/src/cargo/ops/registry.rs b/src/cargo/ops/registry.rs index fe9b52577..68d605a43 100644 --- a/src/cargo/ops/registry.rs +++ b/src/cargo/ops/registry.rs @@ -369,6 +369,10 @@ fn registry( force_update: bool, validate_token: bool, ) -> CargoResult<(Registry, SourceId)> { + if index.is_some() && registry.is_some() { + // Otherwise we would silently ignore one or the other. + bail!("both `--index` and `--registry` should not be set at the same time"); + } // Parse all configuration options let RegistryConfig { token: token_config, diff --git a/tests/testsuite/alt_registry.rs b/tests/testsuite/alt_registry.rs index cf03ab455..3c76d7d6a 100644 --- a/tests/testsuite/alt_registry.rs +++ b/tests/testsuite/alt_registry.rs @@ -1247,3 +1247,19 @@ Caused by: .with_status(101) .run(); } + +#[cargo_test] +fn both_index_and_registry() { + let p = project().file("src/lib.rs", "").build(); + for cmd in &["publish", "owner", "search", "yank --vers 1.0.0"] { + p.cargo(cmd) + .arg("--registry=foo") + .arg("--index=foo") + .with_status(101) + .with_stderr( + "[ERROR] both `--index` and `--registry` \ + should not be set at the same time", + ) + .run(); + } +}