diff --git a/src/bin/cargo/command_prelude.rs b/src/bin/cargo/command_prelude.rs index e7f8d1f4351..c8f2fc824b0 100644 --- a/src/bin/cargo/command_prelude.rs +++ b/src/bin/cargo/command_prelude.rs @@ -6,6 +6,7 @@ use cargo::CargoResult; use cargo::core::Workspace; use cargo::core::compiler::{BuildConfig, MessageFormat}; use cargo::ops::{CompileFilter, CompileOptions, NewOptions, Packages, VersionControl}; +use cargo::sources::CRATES_IO_REGISTRY; use cargo::util::paths; use cargo::util::important_paths::find_root_manifest_for_wd; @@ -361,7 +362,7 @@ pub trait ArgMatchesExt { )); } - if registry == "crates.io" { + if registry == CRATES_IO_REGISTRY { // If "crates.io" is specified then we just need to return None // as that will cause cargo to use crates.io. This is required // for the case where a default alterative registry is used diff --git a/src/cargo/core/package_id.rs b/src/cargo/core/package_id.rs index 7bb64e8a112..568bef5b6c4 100644 --- a/src/cargo/core/package_id.rs +++ b/src/cargo/core/package_id.rs @@ -182,12 +182,12 @@ impl fmt::Debug for PackageId { mod tests { use super::PackageId; use core::source::SourceId; - use sources::CRATES_IO; + use sources::CRATES_IO_INDEX; use util::ToUrl; #[test] fn invalid_version_handled_nicely() { - let loc = CRATES_IO.to_url().unwrap(); + let loc = CRATES_IO_INDEX.to_url().unwrap(); let repo = SourceId::for_registry(&loc).unwrap(); assert!(PackageId::new("foo", "1.0", &repo).is_err()); diff --git a/src/cargo/core/source/source_id.rs b/src/cargo/core/source/source_id.rs index ae037e7a640..f30d18ffd05 100644 --- a/src/cargo/core/source/source_id.rs +++ b/src/cargo/core/source/source_id.rs @@ -12,7 +12,7 @@ use url::Url; use ops; use sources::git; -use sources::{GitSource, PathSource, RegistrySource, CRATES_IO}; +use sources::{GitSource, PathSource, RegistrySource, CRATES_IO_INDEX}; use sources::DirectorySource; use util::{CargoResult, Config, ToUrl}; @@ -184,7 +184,7 @@ impl SourceId { } &index[..] } else { - CRATES_IO + CRATES_IO_INDEX }; let url = url.to_url()?; SourceId::for_registry(&url) @@ -302,7 +302,7 @@ impl SourceId { Kind::Registry => {} _ => return false, } - self.inner.url.to_string() == CRATES_IO + self.inner.url.to_string() == CRATES_IO_INDEX } /// Hash `self` diff --git a/src/cargo/ops/cargo_new.rs b/src/cargo/ops/cargo_new.rs index adc60829de1..bd2bc4073cc 100644 --- a/src/cargo/ops/cargo_new.rs +++ b/src/cargo/ops/cargo_new.rs @@ -543,8 +543,7 @@ name = "{}" version = "0.1.0" authors = [{}] edition = {} -publish = {} - +{} [dependencies] {}"#, name, @@ -554,8 +553,12 @@ publish = {} None => toml::Value::String("2018".to_string()), }, match opts.registry { - Some(registry) => toml::Value::Array(vec!(toml::Value::String(registry.to_string()))), - None => toml::Value::Boolean(true), + Some(registry) => { + format!("publish = {}\n", + toml::Value::Array(vec!(toml::Value::String(registry.to_string()))) + ) + } + None => "".to_string(), }, cargotoml_path_specifier ).as_bytes(), diff --git a/src/cargo/sources/config.rs b/src/cargo/sources/config.rs index 991c3c631cc..ca52bc4d2b5 100644 --- a/src/cargo/sources/config.rs +++ b/src/cargo/sources/config.rs @@ -10,7 +10,7 @@ use std::path::{Path, PathBuf}; use url::Url; use core::{GitReference, Source, SourceId}; -use sources::ReplacedSource; +use sources::{ReplacedSource, CRATES_IO_REGISTRY}; use util::{Config, ToUrl}; use util::config::ConfigValue; use util::errors::{CargoResult, CargoResultExt}; @@ -59,7 +59,7 @@ impl<'cfg> SourceConfigMap<'cfg> { config, }; base.add( - "crates-io", + CRATES_IO_REGISTRY, SourceConfig { id: SourceId::crates_io(config)?, replace_with: None, diff --git a/src/cargo/sources/mod.rs b/src/cargo/sources/mod.rs index ed784e95ab4..d96a05639ef 100644 --- a/src/cargo/sources/mod.rs +++ b/src/cargo/sources/mod.rs @@ -2,7 +2,7 @@ pub use self::config::SourceConfigMap; pub use self::directory::DirectorySource; pub use self::git::GitSource; pub use self::path::PathSource; -pub use self::registry::{RegistrySource, CRATES_IO}; +pub use self::registry::{RegistrySource, CRATES_IO_INDEX, CRATES_IO_REGISTRY}; pub use self::replaced::ReplacedSource; pub mod config; diff --git a/src/cargo/sources/registry/mod.rs b/src/cargo/sources/registry/mod.rs index 76afec1c427..b061716f8f9 100644 --- a/src/cargo/sources/registry/mod.rs +++ b/src/cargo/sources/registry/mod.rs @@ -179,7 +179,8 @@ use util::to_url::ToUrl; use util::{internal, CargoResult, Config, FileLock, Filesystem}; const INDEX_LOCK: &str = ".cargo-index-lock"; -pub const CRATES_IO: &str = "https://github.com/rust-lang/crates.io-index"; +pub const CRATES_IO_INDEX: &str = "https://github.com/rust-lang/crates.io-index"; +pub const CRATES_IO_REGISTRY: &str = "crates-io"; const CRATE_TEMPLATE: &str = "{crate}"; const VERSION_TEMPLATE: &str = "{version}"; diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 79b68189a2d..4f42a7335c4 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -18,7 +18,7 @@ use core::profiles::Profiles; use core::{Dependency, Manifest, PackageId, Summary, Target}; use core::{Edition, EitherManifest, Feature, Features, VirtualManifest}; use core::{GitReference, PackageIdSpec, SourceId, WorkspaceConfig, WorkspaceRootConfig}; -use sources::CRATES_IO; +use sources::{CRATES_IO_INDEX, CRATES_IO_REGISTRY}; use util::errors::{CargoError, CargoResult, CargoResultExt}; use util::paths; use util::{self, Config, ToUrl}; @@ -1140,7 +1140,7 @@ impl TomlManifest { ) })?; if spec.url().is_none() { - spec.set_url(CRATES_IO.parse().unwrap()); + spec.set_url(CRATES_IO_INDEX.parse().unwrap()); } let version_specified = match *replacement { @@ -1175,7 +1175,7 @@ impl TomlManifest { let mut patch = HashMap::new(); for (url, deps) in self.patch.iter().flat_map(|x| x) { let url = match &url[..] { - "crates-io" => CRATES_IO.parse().unwrap(), + CRATES_IO_REGISTRY => CRATES_IO_INDEX.parse().unwrap(), _ => url.to_url()?, }; patch.insert(