Skip to content

Commit 9244a42

Browse files
committed
Reuse crate-io constant
1 parent 4e143fd commit 9244a42

File tree

8 files changed

+19
-13
lines changed

8 files changed

+19
-13
lines changed

src/cargo/core/compiler/rustdoc.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ use std::fmt;
1111
use std::hash;
1212
use url::Url;
1313

14+
const DOCS_RS_URL: &'static str = "https://docs.rs/";
15+
1416
/// Mode used for `std`.
1517
#[derive(Debug, Hash)]
1618
pub enum RustdocExternMode {
@@ -63,7 +65,7 @@ pub struct RustdocExternMap {
6365
impl Default for RustdocExternMap {
6466
fn default() -> Self {
6567
let mut registries = HashMap::new();
66-
registries.insert("crates-io".into(), "https://docs.rs/".into());
68+
registries.insert(CRATES_IO_REGISTRY.into(), DOCS_RS_URL.into());
6769
Self {
6870
registries,
6971
std: None,
@@ -76,8 +78,8 @@ fn default_crates_io_to_docs_rs<'de, D: serde::Deserializer<'de>>(
7678
) -> Result<HashMap<String, String>, D::Error> {
7779
use serde::Deserialize;
7880
let mut registries = HashMap::deserialize(de)?;
79-
if !registries.contains_key("crates-io") {
80-
registries.insert("crates-io".into(), "https://docs.rs/".into());
81+
if !registries.contains_key(CRATES_IO_REGISTRY) {
82+
registries.insert(CRATES_IO_REGISTRY.into(), DOCS_RS_URL.into());
8183
}
8284
Ok(registries)
8385
}

src/cargo/core/source/source_id.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::core::PackageId;
2-
use crate::sources::DirectorySource;
3-
use crate::sources::{GitSource, PathSource, RegistrySource, CRATES_IO_INDEX};
2+
use crate::sources::{DirectorySource, CRATES_IO_DOMAIN, CRATES_IO_INDEX};
3+
use crate::sources::{GitSource, PathSource, RegistrySource};
44
use crate::util::{CanonicalUrl, CargoResult, Config, IntoUrl};
55
use log::trace;
66
use serde::de;
@@ -224,7 +224,7 @@ impl SourceId {
224224

225225
pub fn display_registry_name(self) -> String {
226226
if self.is_default_registry() {
227-
"crates.io".to_string()
227+
CRATES_IO_DOMAIN.to_string()
228228
} else if let Some(name) = &self.inner.name {
229229
name.clone()
230230
} else {

src/cargo/ops/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use crate::sources::CRATES_IO_DOMAIN;
2+
13
pub use self::cargo_clean::{clean, CleanOptions};
24
pub use self::cargo_compile::{
35
compile, compile_with_exec, compile_ws, create_bcx, print, resolve_all_features, CompileOptions,
@@ -66,7 +68,7 @@ fn check_dep_has_version(dep: &crate::core::Dependency, publish: bool) -> crate:
6668

6769
if !dep.specified_req() && dep.is_transitive() {
6870
let dep_version_source = dep.registry_id().map_or_else(
69-
|| "crates.io".to_string(),
71+
|| CRATES_IO_DOMAIN.to_string(),
7072
|registry_id| registry_id.display_registry_name(),
7173
);
7274
anyhow::bail!(

src/cargo/ops/registry.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::core::resolver::CliFeatures;
2020
use crate::core::source::Source;
2121
use crate::core::{Package, SourceId, Workspace};
2222
use crate::ops;
23-
use crate::sources::{RegistrySource, SourceConfigMap, CRATES_IO_REGISTRY};
23+
use crate::sources::{RegistrySource, SourceConfigMap, CRATES_IO_DOMAIN, CRATES_IO_REGISTRY};
2424
use crate::util::config::{self, Config, SslVersionConfig, SslVersionConfigRange};
2525
use crate::util::errors::CargoResult;
2626
use crate::util::important_paths::find_root_manifest_for_wd;
@@ -730,15 +730,15 @@ pub fn registry_login(
730730
"Login",
731731
format!(
732732
"token for `{}` saved",
733-
reg.as_ref().map_or("crates.io", String::as_str)
733+
reg.as_ref().map_or(CRATES_IO_DOMAIN, String::as_str)
734734
),
735735
)?;
736736
Ok(())
737737
}
738738

739739
pub fn registry_logout(config: &Config, reg: Option<String>) -> CargoResult<()> {
740740
let (registry, reg_cfg, _) = registry(config, None, None, reg.clone(), false, false)?;
741-
let reg_name = reg.as_deref().unwrap_or("crates.io");
741+
let reg_name = reg.as_deref().unwrap_or(CRATES_IO_DOMAIN);
742742
if reg_cfg.credential_process.is_none() && reg_cfg.token.is_none() {
743743
config.shell().status(
744744
"Logout",

src/cargo/ops/vendor.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::core::shell::Verbosity;
22
use crate::core::{GitReference, Workspace};
33
use crate::ops;
44
use crate::sources::path::PathSource;
5+
use crate::sources::CRATES_IO_REGISTRY;
56
use crate::util::{CargoResult, Config};
67
use anyhow::{bail, Context as _};
78
use cargo_util::{paths, Sha256};
@@ -248,7 +249,7 @@ fn sync(
248249
// replace original sources with vendor
249250
for source_id in sources {
250251
let name = if source_id.is_default_registry() {
251-
"crates-io".to_string()
252+
CRATES_IO_REGISTRY.to_string()
252253
} else {
253254
source_id.url().to_string()
254255
};

src/cargo/sources/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ restore the source replacement configuration to continue the build
247247
check_not_set("tag", def.tag)?;
248248
check_not_set("rev", def.rev)?;
249249
}
250-
if name == "crates-io" && srcs.is_empty() {
250+
if name == CRATES_IO_REGISTRY && srcs.is_empty() {
251251
srcs.push(SourceId::crates_io(self.config)?);
252252
}
253253

src/cargo/sources/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ pub use self::config::SourceConfigMap;
22
pub use self::directory::DirectorySource;
33
pub use self::git::GitSource;
44
pub use self::path::PathSource;
5-
pub use self::registry::{RegistrySource, CRATES_IO_INDEX, CRATES_IO_REGISTRY};
5+
pub use self::registry::{RegistrySource, CRATES_IO_DOMAIN, CRATES_IO_INDEX, CRATES_IO_REGISTRY};
66
pub use self::replaced::ReplacedSource;
77

88
pub mod config;

src/cargo/sources/registry/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ use crate::util::{restricted_names, CargoResult, Config, Filesystem, OptVersionR
184184
const PACKAGE_SOURCE_LOCK: &str = ".cargo-ok";
185185
pub const CRATES_IO_INDEX: &str = "https://github.com/rust-lang/crates.io-index";
186186
pub const CRATES_IO_REGISTRY: &str = "crates-io";
187+
pub const CRATES_IO_DOMAIN: &str = "crates.io";
187188
const CRATE_TEMPLATE: &str = "{crate}";
188189
const VERSION_TEMPLATE: &str = "{version}";
189190
const PREFIX_TEMPLATE: &str = "{prefix}";

0 commit comments

Comments
 (0)