Skip to content

Commit 8e11d86

Browse files
committedApr 4, 2023
Auto merge of #11930 - arlosi:sparse-warning, r=epage
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: ``` warning: unused config key `registries.crates-io.protocol` in [..] ``` This fixes the issue by adding the field to the `RegistryConfig` struct.
2 parents 23e3d8b + a1cba8f commit 8e11d86

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed
 

‎src/cargo/util/auth.rs

+2
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ pub fn registry_credential_config(
133133
secret_key_subject: Option<String>,
134134
#[serde(rename = "default")]
135135
_default: Option<String>,
136+
#[serde(rename = "protocol")]
137+
_protocol: Option<String>,
136138
}
137139

138140
log::trace!("loading credential config for {}", sid);

‎tests/testsuite/alt_registry.rs

+27
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,33 @@ or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN",
437437
.run();
438438
}
439439

440+
#[cargo_test]
441+
fn cargo_registries_crates_io_protocol() {
442+
let _ = RegistryBuilder::new()
443+
.no_configure_token()
444+
.alternative()
445+
.build();
446+
// Should not produce a warning due to the registries.crates-io.protocol = 'sparse' configuration
447+
let p = project()
448+
.file("src/lib.rs", "")
449+
.file(
450+
".cargo/config.toml",
451+
"[registries.crates-io]
452+
protocol = 'sparse'",
453+
)
454+
.build();
455+
456+
p.cargo("publish --registry alternative")
457+
.with_status(101)
458+
.with_stderr(
459+
"\
460+
[UPDATING] `alternative` index
461+
error: no token found for `alternative`, please run `cargo login --registry alternative`
462+
or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN",
463+
)
464+
.run();
465+
}
466+
440467
#[cargo_test]
441468
fn publish_to_alt_registry() {
442469
let _reg = RegistryBuilder::new()

0 commit comments

Comments
 (0)
Please sign in to comment.