From 0b653a43ba49ebd67d04dc23cb4071d569a8671e Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sat, 11 Jan 2020 11:04:13 -0800 Subject: [PATCH] Rename `Kind` --- crates/resolver-tests/src/lib.rs | 32 ++++---- crates/resolver-tests/tests/resolve.rs | 36 +++++---- src/cargo/core/compiler/unit_dependencies.rs | 2 +- src/cargo/core/dependency.rs | 30 ++++---- src/cargo/core/resolver/resolve.rs | 4 +- src/cargo/core/source/source_id.rs | 77 ++++++++++---------- src/cargo/ops/cargo_output_metadata.rs | 2 +- src/cargo/ops/registry.rs | 8 +- src/cargo/sources/registry/mod.rs | 8 +- src/cargo/util/toml/mod.rs | 18 ++--- 10 files changed, 111 insertions(+), 106 deletions(-) diff --git a/crates/resolver-tests/src/lib.rs b/crates/resolver-tests/src/lib.rs index f7dbe52c407..ef47f11ffc5 100644 --- a/crates/resolver-tests/src/lib.rs +++ b/crates/resolver-tests/src/lib.rs @@ -10,7 +10,7 @@ use std::fmt::Write; use std::rc::Rc; use std::time::Instant; -use cargo::core::dependency::Kind; +use cargo::core::dependency::DepKind; use cargo::core::resolver::{self, ResolveOpts}; use cargo::core::source::{GitReference, SourceId}; use cargo::core::Resolve; @@ -629,7 +629,7 @@ pub fn dep(name: &str) -> Dependency { pub fn dep_req(name: &str, req: &str) -> Dependency { Dependency::parse_no_deprecated(name, Some(req), registry_loc()).unwrap() } -pub fn dep_req_kind(name: &str, req: &str, kind: Kind, public: bool) -> Dependency { +pub fn dep_req_kind(name: &str, req: &str, kind: DepKind, public: bool) -> Dependency { let mut dep = dep_req(name, req); dep.set_kind(kind); dep.set_public(public); @@ -642,7 +642,7 @@ pub fn dep_loc(name: &str, location: &str) -> Dependency { let source_id = SourceId::for_git(&url, master).unwrap(); Dependency::parse_no_deprecated(name, Some("1.0.0"), source_id).unwrap() } -pub fn dep_kind(name: &str, kind: Kind) -> Dependency { +pub fn dep_kind(name: &str, kind: DepKind) -> Dependency { dep(name).set_kind(kind).clone() } @@ -677,12 +677,12 @@ impl fmt::Debug for PrettyPrintRegistry { } else { write!(f, "pkg!((\"{}\", \"{}\") => [", s.name(), s.version())?; for d in s.dependencies() { - if d.kind() == Kind::Normal + if d.kind() == DepKind::Normal && &d.version_req().to_string() == "*" && !d.is_public() { write!(f, "dep(\"{}\"),", d.name_in_toml())?; - } else if d.kind() == Kind::Normal && !d.is_public() { + } else if d.kind() == DepKind::Normal && !d.is_public() { write!( f, "dep_req(\"{}\", \"{}\"),", @@ -696,9 +696,9 @@ impl fmt::Debug for PrettyPrintRegistry { d.name_in_toml(), d.version_req(), match d.kind() { - Kind::Development => "Kind::Development", - Kind::Build => "Kind::Build", - Kind::Normal => "Kind::Normal", + DepKind::Development => "DepKind::Development", + DepKind::Build => "DepKind::Build", + DepKind::Normal => "DepKind::Normal", }, d.is_public() )?; @@ -725,8 +725,8 @@ fn meta_test_deep_pretty_print_registry() { pkg!(("bar", "2.0.0") => [dep_req("baz", "=1.0.1")]), pkg!(("baz", "1.0.2") => [dep_req("other", "2")]), pkg!(("baz", "1.0.1")), - pkg!(("cat", "1.0.2") => [dep_req_kind("other", "2", Kind::Build, false)]), - pkg!(("cat", "1.0.3") => [dep_req_kind("other", "2", Kind::Development, false)]), + pkg!(("cat", "1.0.2") => [dep_req_kind("other", "2", DepKind::Build, false)]), + pkg!(("cat", "1.0.3") => [dep_req_kind("other", "2", DepKind::Development, false)]), pkg!(("dep_req", "1.0.0")), pkg!(("dep_req", "2.0.0")), ]) @@ -738,8 +738,8 @@ fn meta_test_deep_pretty_print_registry() { pkg!((\"bar\", \"2.0.0\") => [dep_req(\"baz\", \"= 1.0.1\"),]),\ pkg!((\"baz\", \"1.0.2\") => [dep_req(\"other\", \"^2\"),]),\ pkg!((\"baz\", \"1.0.1\")),\ - pkg!((\"cat\", \"1.0.2\") => [dep_req_kind(\"other\", \"^2\", Kind::Build, false),]),\ - pkg!((\"cat\", \"1.0.3\") => [dep_req_kind(\"other\", \"^2\", Kind::Development, false),]),\ + pkg!((\"cat\", \"1.0.2\") => [dep_req_kind(\"other\", \"^2\", DepKind::Build, false),]),\ + pkg!((\"cat\", \"1.0.3\") => [dep_req_kind(\"other\", \"^2\", DepKind::Development, false),]),\ pkg!((\"dep_req\", \"1.0.0\")),\ pkg!((\"dep_req\", \"2.0.0\")),]" ) @@ -848,10 +848,10 @@ pub fn registry_strategy( format!(">={}, <={}", s[c].0, s[d].0) }, match k { - 0 => Kind::Normal, - 1 => Kind::Build, - // => Kind::Development, // Development has no impact so don't gen - _ => panic!("bad index for Kind"), + 0 => DepKind::Normal, + 1 => DepKind::Build, + // => DepKind::Development, // Development has no impact so don't gen + _ => panic!("bad index for DepKind"), }, p && k == 0, )) diff --git a/crates/resolver-tests/tests/resolve.rs b/crates/resolver-tests/tests/resolve.rs index fb529582187..93e1ff4a1a9 100644 --- a/crates/resolver-tests/tests/resolve.rs +++ b/crates/resolver-tests/tests/resolve.rs @@ -1,4 +1,4 @@ -use cargo::core::dependency::Kind; +use cargo::core::dependency::DepKind; use cargo::core::{enable_nightly_features, Dependency}; use cargo::util::{is_ci, Config}; @@ -232,7 +232,7 @@ fn pub_fail() { let input = vec![ pkg!(("a", "0.0.4")), pkg!(("a", "0.0.5")), - pkg!(("e", "0.0.6") => [dep_req_kind("a", "<= 0.0.4", Kind::Normal, true),]), + pkg!(("e", "0.0.6") => [dep_req_kind("a", "<= 0.0.4", DepKind::Normal, true),]), pkg!(("kB", "0.0.3") => [dep_req("a", ">= 0.0.5"),dep("e"),]), ]; let reg = registry(input); @@ -244,7 +244,7 @@ fn basic_public_dependency() { let reg = registry(vec![ pkg!(("A", "0.1.0")), pkg!(("A", "0.2.0")), - pkg!("B" => [dep_req_kind("A", "0.1", Kind::Normal, true)]), + pkg!("B" => [dep_req_kind("A", "0.1", DepKind::Normal, true)]), pkg!("C" => [dep("A"), dep("B")]), ]); @@ -279,7 +279,7 @@ fn public_dependency_filling_in() { pkg!(("a", "0.1.1")), pkg!(("b", "0.0.0") => [dep("bad")]), pkg!(("b", "0.0.1") => [dep("bad")]), - pkg!(("b", "0.0.2") => [dep_req_kind("a", "=0.0.6", Kind::Normal, true)]), + pkg!(("b", "0.0.2") => [dep_req_kind("a", "=0.0.6", DepKind::Normal, true)]), pkg!("c" => [dep_req("b", ">=0.0.1")]), pkg!("d" => [dep("c"), dep("a"), dep("b")]), ]); @@ -315,7 +315,7 @@ fn public_dependency_filling_in_and_update() { let reg = registry(vec![ pkg!(("A", "0.0.0")), pkg!(("A", "0.0.2")), - pkg!("B" => [dep_req_kind("A", "=0.0.0", Kind::Normal, true),]), + pkg!("B" => [dep_req_kind("A", "=0.0.0", DepKind::Normal, true),]), pkg!("C" => [dep("A"),dep("B")]), pkg!("D" => [dep("B"),dep("C")]), ]); @@ -341,7 +341,7 @@ fn public_dependency_skipping() { pkg!(("a", "0.2.0")), pkg!(("a", "2.0.0")), pkg!(("b", "0.0.0") => [dep("bad")]), - pkg!(("b", "0.2.1") => [dep_req_kind("a", "0.2.0", Kind::Normal, true)]), + pkg!(("b", "0.2.1") => [dep_req_kind("a", "0.2.0", DepKind::Normal, true)]), pkg!("c" => [dep("a"),dep("b")]), ]; let reg = registry(input); @@ -361,7 +361,7 @@ fn public_dependency_skipping_in_backtracking() { pkg!(("A", "0.0.3") => [dep("bad")]), pkg!(("A", "0.0.4")), pkg!(("A", "0.0.5")), - pkg!("B" => [dep_req_kind("A", ">= 0.0.3", Kind::Normal, true)]), + pkg!("B" => [dep_req_kind("A", ">= 0.0.3", DepKind::Normal, true)]), pkg!("C" => [dep_req("A", "<= 0.0.4"), dep("B")]), ]; let reg = registry(input); @@ -374,9 +374,9 @@ fn public_sat_topological_order() { let input = vec![ pkg!(("a", "0.0.1")), pkg!(("a", "0.0.0")), - pkg!(("b", "0.0.1") => [dep_req_kind("a", "= 0.0.1", Kind::Normal, true),]), + pkg!(("b", "0.0.1") => [dep_req_kind("a", "= 0.0.1", DepKind::Normal, true),]), pkg!(("b", "0.0.0") => [dep("bad"),]), - pkg!("A" => [dep_req("a", "= 0.0.0"),dep_req_kind("b", "*", Kind::Normal, true)]), + pkg!("A" => [dep_req("a", "= 0.0.0"),dep_req_kind("b", "*", DepKind::Normal, true)]), ]; let reg = registry(input); @@ -388,7 +388,7 @@ fn public_sat_unused_makes_things_pub() { let input = vec![ pkg!(("a", "0.0.1")), pkg!(("a", "0.0.0")), - pkg!(("b", "8.0.1") => [dep_req_kind("a", "= 0.0.1", Kind::Normal, true),]), + pkg!(("b", "8.0.1") => [dep_req_kind("a", "= 0.0.1", DepKind::Normal, true),]), pkg!(("b", "8.0.0") => [dep_req("a", "= 0.0.1"),]), pkg!("c" => [dep_req("b", "= 8.0.0"),dep_req("a", "= 0.0.0"),]), ]; @@ -403,8 +403,8 @@ fn public_sat_unused_makes_things_pub_2() { pkg!(("c", "0.0.2")), pkg!(("c", "0.0.1")), pkg!(("a-sys", "0.0.2")), - pkg!(("a-sys", "0.0.1") => [dep_req_kind("c", "= 0.0.1", Kind::Normal, true),]), - pkg!("P" => [dep_req_kind("a-sys", "*", Kind::Normal, true),dep_req("c", "= 0.0.1"),]), + pkg!(("a-sys", "0.0.1") => [dep_req_kind("c", "= 0.0.1", DepKind::Normal, true),]), + pkg!("P" => [dep_req_kind("a-sys", "*", DepKind::Normal, true),dep_req("c", "= 0.0.1"),]), pkg!("A" => [dep("P"),dep_req("c", "= 0.0.2"),]), ]; let reg = registry(input); @@ -492,13 +492,17 @@ fn test_resolving_with_same_name() { #[test] fn test_resolving_with_dev_deps() { let reg = registry(vec![ - pkg!("foo" => ["bar", dep_kind("baz", Kind::Development)]), - pkg!("baz" => ["bat", dep_kind("bam", Kind::Development)]), + pkg!("foo" => ["bar", dep_kind("baz", DepKind::Development)]), + pkg!("baz" => ["bat", dep_kind("bam", DepKind::Development)]), pkg!("bar"), pkg!("bat"), ]); - let res = resolve(vec![dep("foo"), dep_kind("baz", Kind::Development)], ®).unwrap(); + let res = resolve( + vec![dep("foo"), dep_kind("baz", DepKind::Development)], + ®, + ) + .unwrap(); assert_same(&res, &names(&["root", "foo", "bar", "baz", "bat"])); } @@ -1061,7 +1065,7 @@ fn resolving_with_public_constrained_sibling() { dep_req("backtrack_trap1", "1.0"), dep_req("backtrack_trap2", "1.0"), dep_req("constrained", "<=60")]), - pkg!(("bar", "1.0.0") => [dep_req_kind("constrained", ">=60", Kind::Normal, true)]), + pkg!(("bar", "1.0.0") => [dep_req_kind("constrained", ">=60", DepKind::Normal, true)]), ]; // Bump these to make the test harder, but you'll also need to // change the version constraints on `constrained` above. To correctly diff --git a/src/cargo/core/compiler/unit_dependencies.rs b/src/cargo/core/compiler/unit_dependencies.rs index a57fecf5f17..5c1f5466ff2 100644 --- a/src/cargo/core/compiler/unit_dependencies.rs +++ b/src/cargo/core/compiler/unit_dependencies.rs @@ -17,7 +17,7 @@ use crate::core::compiler::Unit; use crate::core::compiler::{BuildContext, CompileKind, CompileMode}; -use crate::core::dependency::Kind as DepKind; +use crate::core::dependency::DepKind; use crate::core::package::Downloads; use crate::core::profiles::{Profile, UnitFor}; use crate::core::resolver::Resolve; diff --git a/src/cargo/core/dependency.rs b/src/cargo/core/dependency.rs index 48b1a2eb2ef..82da0612925 100644 --- a/src/cargo/core/dependency.rs +++ b/src/cargo/core/dependency.rs @@ -32,7 +32,7 @@ struct Inner { registry_id: Option, req: VersionReq, specified_req: bool, - kind: Kind, + kind: DepKind, only_match_name: bool, explicit_name_in_toml: Option, @@ -51,7 +51,7 @@ struct SerializedDependency<'a> { name: &'a str, source: SourceId, req: String, - kind: Kind, + kind: DepKind, rename: Option<&'a str>, optional: bool, @@ -86,7 +86,7 @@ impl ser::Serialize for Dependency { } #[derive(PartialEq, Eq, Hash, Ord, PartialOrd, Clone, Debug, Copy)] -pub enum Kind { +pub enum DepKind { Normal, Development, Build, @@ -138,15 +138,15 @@ this warning. } } -impl ser::Serialize for Kind { +impl ser::Serialize for DepKind { fn serialize(&self, s: S) -> Result where S: ser::Serializer, { match *self { - Kind::Normal => None, - Kind::Development => Some("dev"), - Kind::Build => Some("build"), + DepKind::Normal => None, + DepKind::Development => Some("dev"), + DepKind::Build => Some("build"), } .serialize(s) } @@ -208,7 +208,7 @@ impl Dependency { source_id, registry_id: None, req: VersionReq::any(), - kind: Kind::Normal, + kind: DepKind::Normal, only_match_name: true, optional: false, public: false, @@ -284,7 +284,7 @@ impl Dependency { self } - pub fn kind(&self) -> Kind { + pub fn kind(&self) -> DepKind { self.inner.kind } @@ -296,7 +296,7 @@ impl Dependency { pub fn set_public(&mut self, public: bool) -> &mut Dependency { if public { // Setting 'public' only makes sense for normal dependencies - assert_eq!(self.kind(), Kind::Normal); + assert_eq!(self.kind(), DepKind::Normal); } Rc::make_mut(&mut self.inner).public = public; self @@ -320,10 +320,10 @@ impl Dependency { self.inner.explicit_name_in_toml } - pub fn set_kind(&mut self, kind: Kind) -> &mut Dependency { + pub fn set_kind(&mut self, kind: DepKind) -> &mut Dependency { if self.is_public() { // Setting 'public' only makes sense for normal dependencies - assert_eq!(kind, Kind::Normal); + assert_eq!(kind, DepKind::Normal); } Rc::make_mut(&mut self.inner).kind = kind; self @@ -400,14 +400,14 @@ impl Dependency { /// Returns `false` if the dependency is only used to build the local package. pub fn is_transitive(&self) -> bool { match self.inner.kind { - Kind::Normal | Kind::Build => true, - Kind::Development => false, + DepKind::Normal | DepKind::Build => true, + DepKind::Development => false, } } pub fn is_build(&self) -> bool { match self.inner.kind { - Kind::Build => true, + DepKind::Build => true, _ => false, } } diff --git a/src/cargo/core/resolver/resolve.rs b/src/cargo/core/resolver/resolve.rs index 78703fa9c41..67fb8341a00 100644 --- a/src/cargo/core/resolver/resolve.rs +++ b/src/cargo/core/resolver/resolve.rs @@ -4,7 +4,7 @@ use std::collections::{HashMap, HashSet}; use std::fmt; use std::iter::FromIterator; -use crate::core::dependency::Kind; +use crate::core::dependency::DepKind; use crate::core::{Dependency, PackageId, PackageIdSpec, Summary, Target}; use crate::util::errors::CargoResult; use crate::util::Graph; @@ -87,7 +87,7 @@ impl Resolve { .edges(p) .filter(|(_, deps)| { deps.iter() - .any(|d| d.kind() == Kind::Normal && d.is_public()) + .any(|d| d.kind() == DepKind::Normal && d.is_public()) }) .map(|(dep_package, _)| *dep_package) .collect::>(); diff --git a/src/cargo/core/source/source_id.rs b/src/cargo/core/source/source_id.rs index a864954edac..a5fe26e354b 100644 --- a/src/cargo/core/source/source_id.rs +++ b/src/cargo/core/source/source_id.rs @@ -36,7 +36,7 @@ struct SourceIdInner { /// The canonical version of the above url canonical_url: CanonicalUrl, /// The source kind. - kind: Kind, + kind: SourceKind, /// For example, the exact Git revision of the specified branch for a Git Source. precise: Option, /// Name of the registry source for alternative registries @@ -48,7 +48,7 @@ struct SourceIdInner { /// The possible kinds of code source. Along with `SourceIdInner`, this fully defines the /// source. #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] -enum Kind { +enum SourceKind { /// A git repository. Git(GitReference), /// A local path.. @@ -76,7 +76,7 @@ impl SourceId { /// Creates a `SourceId` object from the kind and URL. /// /// The canonical url will be calculated, but the precise field will not - fn new(kind: Kind, url: Url) -> CargoResult { + fn new(kind: SourceKind, url: Url) -> CargoResult { let source_id = SourceId::wrap(SourceIdInner { kind, canonical_url: CanonicalUrl::new(&url)?, @@ -135,11 +135,12 @@ impl SourceId { } "registry" => { let url = url.into_url()?; - Ok(SourceId::new(Kind::Registry, url)?.with_precise(Some("locked".to_string()))) + Ok(SourceId::new(SourceKind::Registry, url)? + .with_precise(Some("locked".to_string()))) } "path" => { let url = url.into_url()?; - SourceId::new(Kind::Path, url) + SourceId::new(SourceKind::Path, url) } kind => Err(anyhow::format_err!("unsupported source protocol: {}", kind)), } @@ -157,29 +158,29 @@ impl SourceId { /// `path`: an absolute path. pub fn for_path(path: &Path) -> CargoResult { let url = path.into_url()?; - SourceId::new(Kind::Path, url) + SourceId::new(SourceKind::Path, url) } /// Creates a `SourceId` from a Git reference. pub fn for_git(url: &Url, reference: GitReference) -> CargoResult { - SourceId::new(Kind::Git(reference), url.clone()) + SourceId::new(SourceKind::Git(reference), url.clone()) } /// Creates a SourceId from a registry URL. pub fn for_registry(url: &Url) -> CargoResult { - SourceId::new(Kind::Registry, url.clone()) + SourceId::new(SourceKind::Registry, url.clone()) } /// Creates a SourceId from a local registry path. pub fn for_local_registry(path: &Path) -> CargoResult { let url = path.into_url()?; - SourceId::new(Kind::LocalRegistry, url) + SourceId::new(SourceKind::LocalRegistry, url) } /// Creates a `SourceId` from a directory path. pub fn for_directory(path: &Path) -> CargoResult { let url = path.into_url()?; - SourceId::new(Kind::Directory, url) + SourceId::new(SourceKind::Directory, url) } /// Returns the `SourceId` corresponding to the main repository. @@ -211,7 +212,7 @@ impl SourceId { pub fn alt_registry(config: &Config, key: &str) -> CargoResult { let url = config.get_registry_index(key)?; Ok(SourceId::wrap(SourceIdInner { - kind: Kind::Registry, + kind: SourceKind::Registry, canonical_url: CanonicalUrl::new(&url)?, url, precise: None, @@ -250,13 +251,13 @@ impl SourceId { /// Returns `true` if this source is from a filesystem path. pub fn is_path(self) -> bool { - self.inner.kind == Kind::Path + self.inner.kind == SourceKind::Path } /// Returns `true` if this source is from a registry (either local or not). pub fn is_registry(self) -> bool { match self.inner.kind { - Kind::Registry | Kind::LocalRegistry => true, + SourceKind::Registry | SourceKind::LocalRegistry => true, _ => false, } } @@ -267,7 +268,7 @@ impl SourceId { /// necessarily "remote". This just means it is not `local-registry`. pub fn is_remote_registry(self) -> bool { match self.inner.kind { - Kind::Registry => true, + SourceKind::Registry => true, _ => false, } } @@ -275,7 +276,7 @@ impl SourceId { /// Returns `true` if this source from a Git repository. pub fn is_git(self) -> bool { match self.inner.kind { - Kind::Git(_) => true, + SourceKind::Git(_) => true, _ => false, } } @@ -288,20 +289,20 @@ impl SourceId { ) -> CargoResult> { trace!("loading SourceId; {}", self); match self.inner.kind { - Kind::Git(..) => Ok(Box::new(GitSource::new(self, config)?)), - Kind::Path => { + SourceKind::Git(..) => Ok(Box::new(GitSource::new(self, config)?)), + SourceKind::Path => { let path = match self.inner.url.to_file_path() { Ok(p) => p, Err(()) => panic!("path sources cannot be remote"), }; Ok(Box::new(PathSource::new(&path, self, config))) } - Kind::Registry => Ok(Box::new(RegistrySource::remote( + SourceKind::Registry => Ok(Box::new(RegistrySource::remote( self, yanked_whitelist, config, ))), - Kind::LocalRegistry => { + SourceKind::LocalRegistry => { let path = match self.inner.url.to_file_path() { Ok(p) => p, Err(()) => panic!("path sources cannot be remote"), @@ -313,7 +314,7 @@ impl SourceId { config, ))) } - Kind::Directory => { + SourceKind::Directory => { let path = match self.inner.url.to_file_path() { Ok(p) => p, Err(()) => panic!("path sources cannot be remote"), @@ -331,7 +332,7 @@ impl SourceId { /// Gets the Git reference if this is a git source, otherwise `None`. pub fn git_reference(self) -> Option<&'static GitReference> { match self.inner.kind { - Kind::Git(ref s) => Some(s), + SourceKind::Git(ref s) => Some(s), _ => None, } } @@ -347,7 +348,7 @@ impl SourceId { /// Returns `true` if the remote registry is the standard . pub fn is_default_registry(self) -> bool { match self.inner.kind { - Kind::Registry => {} + SourceKind::Registry => {} _ => return false, } self.inner.url.as_str() == CRATES_IO_INDEX @@ -433,7 +434,7 @@ fn url_display(url: &Url) -> String { impl fmt::Display for SourceId { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self.inner.kind { - Kind::Git(ref reference) => { + SourceKind::Git(ref reference) => { // Don't replace the URL display for git references, // because those are kind of expected to be URLs. write!(f, "{}", self.inner.url)?; @@ -447,10 +448,10 @@ impl fmt::Display for SourceId { } Ok(()) } - Kind::Path => write!(f, "{}", url_display(&self.inner.url)), - Kind::Registry => write!(f, "registry `{}`", url_display(&self.inner.url)), - Kind::LocalRegistry => write!(f, "registry `{}`", url_display(&self.inner.url)), - Kind::Directory => write!(f, "dir {}", url_display(&self.inner.url)), + SourceKind::Path => write!(f, "{}", url_display(&self.inner.url)), + SourceKind::Registry => write!(f, "registry `{}`", url_display(&self.inner.url)), + SourceKind::LocalRegistry => write!(f, "registry `{}`", url_display(&self.inner.url)), + SourceKind::Directory => write!(f, "dir {}", url_display(&self.inner.url)), } } } @@ -470,7 +471,7 @@ impl PartialEq for SourceId { } match (&self.inner.kind, &other.inner.kind) { - (Kind::Git(ref1), Kind::Git(ref2)) => { + (SourceKind::Git(ref1), SourceKind::Git(ref2)) => { ref1 == ref2 && self.inner.canonical_url == other.inner.canonical_url } _ => false, @@ -495,7 +496,7 @@ impl Ord for SourceIdInner { ord => return ord, } match (&self.kind, &other.kind) { - (Kind::Git(ref1), Kind::Git(ref2)) => { + (SourceKind::Git(ref1), SourceKind::Git(ref2)) => { (ref1, &self.canonical_url).cmp(&(ref2, &other.canonical_url)) } _ => self.kind.cmp(&other.kind), @@ -510,7 +511,7 @@ impl Hash for SourceId { fn hash(&self, into: &mut S) { self.inner.kind.hash(into); match self.inner.kind { - Kind::Git(_) => self.inner.canonical_url.hash(into), + SourceKind::Git(_) => self.inner.canonical_url.hash(into), _ => self.inner.url.as_str().hash(into), } } @@ -525,12 +526,12 @@ impl<'a> fmt::Display for SourceIdIntoUrl<'a> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self.inner { SourceIdInner { - kind: Kind::Path, + kind: SourceKind::Path, ref url, .. } => write!(f, "path+{}", url), SourceIdInner { - kind: Kind::Git(ref reference), + kind: SourceKind::Git(ref reference), ref url, ref precise, .. @@ -545,17 +546,17 @@ impl<'a> fmt::Display for SourceIdIntoUrl<'a> { Ok(()) } SourceIdInner { - kind: Kind::Registry, + kind: SourceKind::Registry, ref url, .. } => write!(f, "registry+{}", url), SourceIdInner { - kind: Kind::LocalRegistry, + kind: SourceKind::LocalRegistry, ref url, .. } => write!(f, "local-registry+{}", url), SourceIdInner { - kind: Kind::Directory, + kind: SourceKind::Directory, ref url, .. } => write!(f, "directory+{}", url), @@ -591,13 +592,13 @@ impl<'a> fmt::Display for PrettyRef<'a> { #[cfg(test)] mod tests { - use super::{GitReference, Kind, SourceId}; + use super::{GitReference, SourceId, SourceKind}; use crate::util::IntoUrl; #[test] fn github_sources_equal() { let loc = "https://github.com/foo/bar".into_url().unwrap(); - let master = Kind::Git(GitReference::Branch("master".to_string())); + let master = SourceKind::Git(GitReference::Branch("master".to_string())); let s1 = SourceId::new(master.clone(), loc).unwrap(); let loc = "git://github.com/foo/bar".into_url().unwrap(); @@ -605,7 +606,7 @@ mod tests { assert_eq!(s1, s2); - let foo = Kind::Git(GitReference::Branch("foo".to_string())); + let foo = SourceKind::Git(GitReference::Branch("foo".to_string())); let s3 = SourceId::new(foo, loc).unwrap(); assert_ne!(s1, s3); } diff --git a/src/cargo/ops/cargo_output_metadata.rs b/src/cargo/ops/cargo_output_metadata.rs index 6c3ef3ea8c7..498c217936a 100644 --- a/src/cargo/ops/cargo_output_metadata.rs +++ b/src/cargo/ops/cargo_output_metadata.rs @@ -90,7 +90,7 @@ struct Dep { #[derive(Serialize, PartialEq, Eq, PartialOrd, Ord)] struct DepKindInfo { - kind: dependency::Kind, + kind: dependency::DepKind, target: Option, } diff --git a/src/cargo/ops/registry.rs b/src/cargo/ops/registry.rs index afc6267c5db..18c24a5df2b 100644 --- a/src/cargo/ops/registry.rs +++ b/src/cargo/ops/registry.rs @@ -12,7 +12,7 @@ use curl::easy::{Easy, InfoType, SslOpt, SslVersion}; use log::{log, Level}; use percent_encoding::{percent_encode, NON_ALPHANUMERIC}; -use crate::core::dependency::Kind; +use crate::core::dependency::DepKind; use crate::core::manifest::ManifestMetadata; use crate::core::source::Source; use crate::core::{Package, SourceId, Workspace}; @@ -203,9 +203,9 @@ fn transmit( version_req: dep.version_req().to_string(), target: dep.platform().map(|s| s.to_string()), kind: match dep.kind() { - Kind::Normal => "normal", - Kind::Build => "build", - Kind::Development => "dev", + DepKind::Normal => "normal", + DepKind::Build => "build", + DepKind::Development => "dev", } .to_string(), registry: dep_registry, diff --git a/src/cargo/sources/registry/mod.rs b/src/cargo/sources/registry/mod.rs index 6fadb257fb7..56622902799 100644 --- a/src/cargo/sources/registry/mod.rs +++ b/src/cargo/sources/registry/mod.rs @@ -171,7 +171,7 @@ use semver::{Version, VersionReq}; use serde::Deserialize; use tar::Archive; -use crate::core::dependency::{Dependency, Kind}; +use crate::core::dependency::{DepKind, Dependency}; use crate::core::source::MaybePackage; use crate::core::{InternedString, Package, PackageId, Source, SourceId, Summary}; use crate::sources::PathSource; @@ -316,9 +316,9 @@ impl<'a> RegistryDependency<'a> { dep.set_explicit_name_in_toml(name); } let kind = match kind.as_ref().map(|s| &s[..]).unwrap_or("") { - "dev" => Kind::Development, - "build" => Kind::Build, - _ => Kind::Normal, + "dev" => DepKind::Development, + "build" => DepKind::Build, + _ => DepKind::Normal, }; let platform = match target { diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index df4d8fddffd..f59691d5b73 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -14,7 +14,7 @@ use serde::ser; use serde::{Deserialize, Serialize}; use url::Url; -use crate::core::dependency::Kind; +use crate::core::dependency::DepKind; use crate::core::manifest::{LibKind, ManifestMetadata, TargetSourcePath, Warnings}; use crate::core::profiles::Profiles; use crate::core::{Dependency, InternedString, Manifest, PackageId, Summary, Target}; @@ -1057,7 +1057,7 @@ impl TomlManifest { fn process_dependencies( cx: &mut Context<'_, '_>, new_deps: Option<&BTreeMap>, - kind: Option, + kind: Option, ) -> CargoResult<()> { let dependencies = match new_deps { Some(dependencies) => dependencies, @@ -1077,12 +1077,12 @@ impl TomlManifest { .dev_dependencies .as_ref() .or_else(|| me.dev_dependencies2.as_ref()); - process_dependencies(&mut cx, dev_deps, Some(Kind::Development))?; + process_dependencies(&mut cx, dev_deps, Some(DepKind::Development))?; let build_deps = me .build_dependencies .as_ref() .or_else(|| me.build_dependencies2.as_ref()); - process_dependencies(&mut cx, build_deps, Some(Kind::Build))?; + process_dependencies(&mut cx, build_deps, Some(DepKind::Build))?; for (name, platform) in me.target.iter().flatten() { cx.platform = { @@ -1095,12 +1095,12 @@ impl TomlManifest { .build_dependencies .as_ref() .or_else(|| platform.build_dependencies2.as_ref()); - process_dependencies(&mut cx, build_deps, Some(Kind::Build))?; + process_dependencies(&mut cx, build_deps, Some(DepKind::Build))?; let dev_deps = platform .dev_dependencies .as_ref() .or_else(|| platform.dev_dependencies2.as_ref()); - process_dependencies(&mut cx, dev_deps, Some(Kind::Development))?; + process_dependencies(&mut cx, dev_deps, Some(DepKind::Development))?; } replace = me.replace(&mut cx)?; @@ -1450,7 +1450,7 @@ impl TomlDependency { &self, name: &str, cx: &mut Context<'_, '_>, - kind: Option, + kind: Option, ) -> CargoResult { match *self { TomlDependency::Simple(ref version) => DetailedTomlDependency { @@ -1475,7 +1475,7 @@ impl DetailedTomlDependency { &self, name_in_toml: &str, cx: &mut Context<'_, '_>, - kind: Option, + kind: Option, ) -> CargoResult { if self.version.is_none() && self.path.is_none() && self.git.is_none() { let msg = format!( @@ -1635,7 +1635,7 @@ impl DetailedTomlDependency { if let Some(p) = self.public { cx.features.require(Feature::public_dependency())?; - if dep.kind() != Kind::Normal { + if dep.kind() != DepKind::Normal { bail!("'public' specifier can only be used on regular dependencies, not {:?} dependencies", dep.kind()); }