Skip to content

Commit

Permalink
Auto merge of #11930 - arlosi:sparse-warning, r=epage
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Apr 3, 2023
2 parents ac32aa8 + a1cba8f commit 2168463
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/cargo/util/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ pub fn registry_credential_config(
secret_key_subject: Option<String>,
#[serde(rename = "default")]
_default: Option<String>,
#[serde(rename = "protocol")]
_protocol: Option<String>,
}

log::trace!("loading credential config for {}", sid);
Expand Down
27 changes: 27 additions & 0 deletions tests/testsuite/alt_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 2168463

Please sign in to comment.