From a1cba8fe49dc867d465f0ccad7a3a8789978bcba Mon Sep 17 00:00:00 2001 From: Arlo Siemsen Date: Mon, 3 Apr 2023 11:27:11 -0500 Subject: [PATCH] Fix Cargo warning about unused sparse configuration key When doing a credential lookup, Cargo deserializes the registry configuration and detects the registries.crates-io.protocol key as unused and issues a warning. This fixes the issue by adding the field to the struct --- src/cargo/util/auth.rs | 2 ++ tests/testsuite/alt_registry.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/cargo/util/auth.rs b/src/cargo/util/auth.rs index f7d0fc8c4a2..f45adc6b745 100644 --- a/src/cargo/util/auth.rs +++ b/src/cargo/util/auth.rs @@ -133,6 +133,8 @@ pub fn registry_credential_config( secret_key_subject: Option, #[serde(rename = "default")] _default: Option, + #[serde(rename = "protocol")] + _protocol: Option, } log::trace!("loading credential config for {}", sid); diff --git a/tests/testsuite/alt_registry.rs b/tests/testsuite/alt_registry.rs index 26bd864b008..97da909b83c 100644 --- a/tests/testsuite/alt_registry.rs +++ b/tests/testsuite/alt_registry.rs @@ -437,6 +437,33 @@ or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN", .run(); } +#[cargo_test] +fn cargo_registries_crates_io_protocol() { + let _ = RegistryBuilder::new() + .no_configure_token() + .alternative() + .build(); + // Should not produce a warning due to the registries.crates-io.protocol = 'sparse' configuration + let p = project() + .file("src/lib.rs", "") + .file( + ".cargo/config.toml", + "[registries.crates-io] + protocol = 'sparse'", + ) + .build(); + + p.cargo("publish --registry alternative") + .with_status(101) + .with_stderr( + "\ +[UPDATING] `alternative` index +error: no token found for `alternative`, please run `cargo login --registry alternative` +or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN", + ) + .run(); +} + #[cargo_test] fn publish_to_alt_registry() { let _reg = RegistryBuilder::new()