Skip to content

Commit

Permalink
refactor: use registry_key for getting crates.io key
Browse files Browse the repository at this point in the history
`registry_key` should always be `crates-io` when `is_crates_io()` is true

This also removes the test verifying `Debug` output,
whose format doesn't need to be guaranteed.
  • Loading branch information
weihanglo committed Sep 21, 2023
1 parent d1ffef6 commit 630bbdb
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 40 deletions.
37 changes: 0 additions & 37 deletions src/cargo/core/package_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,43 +251,6 @@ mod tests {
assert!(PackageId::new("foo", "", repo).is_err());
}

#[test]
fn debug() {
let loc = CRATES_IO_INDEX.into_url().unwrap();
let pkg_id = PackageId::new("foo", "1.0.0", SourceId::for_registry(&loc).unwrap()).unwrap();
assert_eq!(
r#"PackageId { name: "foo", version: "1.0.0", source: "registry `crates-io`" }"#,
format!("{:?}", pkg_id)
);

let expected = r#"
PackageId {
name: "foo",
version: "1.0.0",
source: "registry `crates-io`",
}
"#
.trim();

// Can be removed once trailing commas in Debug have reached the stable
// channel.
let expected_without_trailing_comma = r#"
PackageId {
name: "foo",
version: "1.0.0",
source: "registry `crates-io`"
}
"#
.trim();

let actual = format!("{:#?}", pkg_id);
if actual.ends_with(",\n}") {
assert_eq!(actual, expected);
} else {
assert_eq!(actual, expected_without_trailing_comma);
}
}

#[test]
fn display() {
let loc = CRATES_IO_INDEX.into_url().unwrap();
Expand Down
4 changes: 1 addition & 3 deletions src/cargo/core/source_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,7 @@ impl SourceId {

/// Displays the name of a registry if it has one. Otherwise just the URL.
pub fn display_registry_name(self) -> String {
if self.is_crates_io() {
CRATES_IO_REGISTRY.to_string()
} else if let Some(key) = self.inner.registry_key.as_ref().map(|k| k.key()) {
if let Some(key) = self.inner.registry_key.as_ref().map(|k| k.key()) {
key.into()
} else if self.precise().is_some() {
// We remove `precise` here to retrieve an permissive version of
Expand Down

0 comments on commit 630bbdb

Please sign in to comment.