Skip to content

Commit ae08099

Browse files
committed
Auto merge of #7791 - ehuss:rename-kind, r=alexcrichton
Rename `Kind` Rename `dependency::Kind` → `dependency::DepKind` Rename `source_id::Kind` → `source_id::SourceKind` I struggle when there are multiple types with the same name in the same code base. I think this makes it a little clearer what the type is. I was tempted to also rename `registry::Kind`, but I could not think of a good name. That file is particularly hard for me to understand (locked vs normal sources, abstract trait, etc.), so I don't feel comfortable changing it. It's also localized in one file, so not as important.
2 parents 735f648 + 0b653a4 commit ae08099

File tree

10 files changed

+111
-106
lines changed

10 files changed

+111
-106
lines changed

crates/resolver-tests/src/lib.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::fmt::Write;
1010
use std::rc::Rc;
1111
use std::time::Instant;
1212

13-
use cargo::core::dependency::Kind;
13+
use cargo::core::dependency::DepKind;
1414
use cargo::core::resolver::{self, ResolveOpts};
1515
use cargo::core::source::{GitReference, SourceId};
1616
use cargo::core::Resolve;
@@ -629,7 +629,7 @@ pub fn dep(name: &str) -> Dependency {
629629
pub fn dep_req(name: &str, req: &str) -> Dependency {
630630
Dependency::parse_no_deprecated(name, Some(req), registry_loc()).unwrap()
631631
}
632-
pub fn dep_req_kind(name: &str, req: &str, kind: Kind, public: bool) -> Dependency {
632+
pub fn dep_req_kind(name: &str, req: &str, kind: DepKind, public: bool) -> Dependency {
633633
let mut dep = dep_req(name, req);
634634
dep.set_kind(kind);
635635
dep.set_public(public);
@@ -642,7 +642,7 @@ pub fn dep_loc(name: &str, location: &str) -> Dependency {
642642
let source_id = SourceId::for_git(&url, master).unwrap();
643643
Dependency::parse_no_deprecated(name, Some("1.0.0"), source_id).unwrap()
644644
}
645-
pub fn dep_kind(name: &str, kind: Kind) -> Dependency {
645+
pub fn dep_kind(name: &str, kind: DepKind) -> Dependency {
646646
dep(name).set_kind(kind).clone()
647647
}
648648

@@ -677,12 +677,12 @@ impl fmt::Debug for PrettyPrintRegistry {
677677
} else {
678678
write!(f, "pkg!((\"{}\", \"{}\") => [", s.name(), s.version())?;
679679
for d in s.dependencies() {
680-
if d.kind() == Kind::Normal
680+
if d.kind() == DepKind::Normal
681681
&& &d.version_req().to_string() == "*"
682682
&& !d.is_public()
683683
{
684684
write!(f, "dep(\"{}\"),", d.name_in_toml())?;
685-
} else if d.kind() == Kind::Normal && !d.is_public() {
685+
} else if d.kind() == DepKind::Normal && !d.is_public() {
686686
write!(
687687
f,
688688
"dep_req(\"{}\", \"{}\"),",
@@ -696,9 +696,9 @@ impl fmt::Debug for PrettyPrintRegistry {
696696
d.name_in_toml(),
697697
d.version_req(),
698698
match d.kind() {
699-
Kind::Development => "Kind::Development",
700-
Kind::Build => "Kind::Build",
701-
Kind::Normal => "Kind::Normal",
699+
DepKind::Development => "DepKind::Development",
700+
DepKind::Build => "DepKind::Build",
701+
DepKind::Normal => "DepKind::Normal",
702702
},
703703
d.is_public()
704704
)?;
@@ -725,8 +725,8 @@ fn meta_test_deep_pretty_print_registry() {
725725
pkg!(("bar", "2.0.0") => [dep_req("baz", "=1.0.1")]),
726726
pkg!(("baz", "1.0.2") => [dep_req("other", "2")]),
727727
pkg!(("baz", "1.0.1")),
728-
pkg!(("cat", "1.0.2") => [dep_req_kind("other", "2", Kind::Build, false)]),
729-
pkg!(("cat", "1.0.3") => [dep_req_kind("other", "2", Kind::Development, false)]),
728+
pkg!(("cat", "1.0.2") => [dep_req_kind("other", "2", DepKind::Build, false)]),
729+
pkg!(("cat", "1.0.3") => [dep_req_kind("other", "2", DepKind::Development, false)]),
730730
pkg!(("dep_req", "1.0.0")),
731731
pkg!(("dep_req", "2.0.0")),
732732
])
@@ -738,8 +738,8 @@ fn meta_test_deep_pretty_print_registry() {
738738
pkg!((\"bar\", \"2.0.0\") => [dep_req(\"baz\", \"= 1.0.1\"),]),\
739739
pkg!((\"baz\", \"1.0.2\") => [dep_req(\"other\", \"^2\"),]),\
740740
pkg!((\"baz\", \"1.0.1\")),\
741-
pkg!((\"cat\", \"1.0.2\") => [dep_req_kind(\"other\", \"^2\", Kind::Build, false),]),\
742-
pkg!((\"cat\", \"1.0.3\") => [dep_req_kind(\"other\", \"^2\", Kind::Development, false),]),\
741+
pkg!((\"cat\", \"1.0.2\") => [dep_req_kind(\"other\", \"^2\", DepKind::Build, false),]),\
742+
pkg!((\"cat\", \"1.0.3\") => [dep_req_kind(\"other\", \"^2\", DepKind::Development, false),]),\
743743
pkg!((\"dep_req\", \"1.0.0\")),\
744744
pkg!((\"dep_req\", \"2.0.0\")),]"
745745
)
@@ -848,10 +848,10 @@ pub fn registry_strategy(
848848
format!(">={}, <={}", s[c].0, s[d].0)
849849
},
850850
match k {
851-
0 => Kind::Normal,
852-
1 => Kind::Build,
853-
// => Kind::Development, // Development has no impact so don't gen
854-
_ => panic!("bad index for Kind"),
851+
0 => DepKind::Normal,
852+
1 => DepKind::Build,
853+
// => DepKind::Development, // Development has no impact so don't gen
854+
_ => panic!("bad index for DepKind"),
855855
},
856856
p && k == 0,
857857
))

crates/resolver-tests/tests/resolve.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use cargo::core::dependency::Kind;
1+
use cargo::core::dependency::DepKind;
22
use cargo::core::{enable_nightly_features, Dependency};
33
use cargo::util::{is_ci, Config};
44

@@ -232,7 +232,7 @@ fn pub_fail() {
232232
let input = vec![
233233
pkg!(("a", "0.0.4")),
234234
pkg!(("a", "0.0.5")),
235-
pkg!(("e", "0.0.6") => [dep_req_kind("a", "<= 0.0.4", Kind::Normal, true),]),
235+
pkg!(("e", "0.0.6") => [dep_req_kind("a", "<= 0.0.4", DepKind::Normal, true),]),
236236
pkg!(("kB", "0.0.3") => [dep_req("a", ">= 0.0.5"),dep("e"),]),
237237
];
238238
let reg = registry(input);
@@ -244,7 +244,7 @@ fn basic_public_dependency() {
244244
let reg = registry(vec![
245245
pkg!(("A", "0.1.0")),
246246
pkg!(("A", "0.2.0")),
247-
pkg!("B" => [dep_req_kind("A", "0.1", Kind::Normal, true)]),
247+
pkg!("B" => [dep_req_kind("A", "0.1", DepKind::Normal, true)]),
248248
pkg!("C" => [dep("A"), dep("B")]),
249249
]);
250250

@@ -279,7 +279,7 @@ fn public_dependency_filling_in() {
279279
pkg!(("a", "0.1.1")),
280280
pkg!(("b", "0.0.0") => [dep("bad")]),
281281
pkg!(("b", "0.0.1") => [dep("bad")]),
282-
pkg!(("b", "0.0.2") => [dep_req_kind("a", "=0.0.6", Kind::Normal, true)]),
282+
pkg!(("b", "0.0.2") => [dep_req_kind("a", "=0.0.6", DepKind::Normal, true)]),
283283
pkg!("c" => [dep_req("b", ">=0.0.1")]),
284284
pkg!("d" => [dep("c"), dep("a"), dep("b")]),
285285
]);
@@ -315,7 +315,7 @@ fn public_dependency_filling_in_and_update() {
315315
let reg = registry(vec![
316316
pkg!(("A", "0.0.0")),
317317
pkg!(("A", "0.0.2")),
318-
pkg!("B" => [dep_req_kind("A", "=0.0.0", Kind::Normal, true),]),
318+
pkg!("B" => [dep_req_kind("A", "=0.0.0", DepKind::Normal, true),]),
319319
pkg!("C" => [dep("A"),dep("B")]),
320320
pkg!("D" => [dep("B"),dep("C")]),
321321
]);
@@ -341,7 +341,7 @@ fn public_dependency_skipping() {
341341
pkg!(("a", "0.2.0")),
342342
pkg!(("a", "2.0.0")),
343343
pkg!(("b", "0.0.0") => [dep("bad")]),
344-
pkg!(("b", "0.2.1") => [dep_req_kind("a", "0.2.0", Kind::Normal, true)]),
344+
pkg!(("b", "0.2.1") => [dep_req_kind("a", "0.2.0", DepKind::Normal, true)]),
345345
pkg!("c" => [dep("a"),dep("b")]),
346346
];
347347
let reg = registry(input);
@@ -361,7 +361,7 @@ fn public_dependency_skipping_in_backtracking() {
361361
pkg!(("A", "0.0.3") => [dep("bad")]),
362362
pkg!(("A", "0.0.4")),
363363
pkg!(("A", "0.0.5")),
364-
pkg!("B" => [dep_req_kind("A", ">= 0.0.3", Kind::Normal, true)]),
364+
pkg!("B" => [dep_req_kind("A", ">= 0.0.3", DepKind::Normal, true)]),
365365
pkg!("C" => [dep_req("A", "<= 0.0.4"), dep("B")]),
366366
];
367367
let reg = registry(input);
@@ -374,9 +374,9 @@ fn public_sat_topological_order() {
374374
let input = vec![
375375
pkg!(("a", "0.0.1")),
376376
pkg!(("a", "0.0.0")),
377-
pkg!(("b", "0.0.1") => [dep_req_kind("a", "= 0.0.1", Kind::Normal, true),]),
377+
pkg!(("b", "0.0.1") => [dep_req_kind("a", "= 0.0.1", DepKind::Normal, true),]),
378378
pkg!(("b", "0.0.0") => [dep("bad"),]),
379-
pkg!("A" => [dep_req("a", "= 0.0.0"),dep_req_kind("b", "*", Kind::Normal, true)]),
379+
pkg!("A" => [dep_req("a", "= 0.0.0"),dep_req_kind("b", "*", DepKind::Normal, true)]),
380380
];
381381

382382
let reg = registry(input);
@@ -388,7 +388,7 @@ fn public_sat_unused_makes_things_pub() {
388388
let input = vec![
389389
pkg!(("a", "0.0.1")),
390390
pkg!(("a", "0.0.0")),
391-
pkg!(("b", "8.0.1") => [dep_req_kind("a", "= 0.0.1", Kind::Normal, true),]),
391+
pkg!(("b", "8.0.1") => [dep_req_kind("a", "= 0.0.1", DepKind::Normal, true),]),
392392
pkg!(("b", "8.0.0") => [dep_req("a", "= 0.0.1"),]),
393393
pkg!("c" => [dep_req("b", "= 8.0.0"),dep_req("a", "= 0.0.0"),]),
394394
];
@@ -403,8 +403,8 @@ fn public_sat_unused_makes_things_pub_2() {
403403
pkg!(("c", "0.0.2")),
404404
pkg!(("c", "0.0.1")),
405405
pkg!(("a-sys", "0.0.2")),
406-
pkg!(("a-sys", "0.0.1") => [dep_req_kind("c", "= 0.0.1", Kind::Normal, true),]),
407-
pkg!("P" => [dep_req_kind("a-sys", "*", Kind::Normal, true),dep_req("c", "= 0.0.1"),]),
406+
pkg!(("a-sys", "0.0.1") => [dep_req_kind("c", "= 0.0.1", DepKind::Normal, true),]),
407+
pkg!("P" => [dep_req_kind("a-sys", "*", DepKind::Normal, true),dep_req("c", "= 0.0.1"),]),
408408
pkg!("A" => [dep("P"),dep_req("c", "= 0.0.2"),]),
409409
];
410410
let reg = registry(input);
@@ -492,13 +492,17 @@ fn test_resolving_with_same_name() {
492492
#[test]
493493
fn test_resolving_with_dev_deps() {
494494
let reg = registry(vec![
495-
pkg!("foo" => ["bar", dep_kind("baz", Kind::Development)]),
496-
pkg!("baz" => ["bat", dep_kind("bam", Kind::Development)]),
495+
pkg!("foo" => ["bar", dep_kind("baz", DepKind::Development)]),
496+
pkg!("baz" => ["bat", dep_kind("bam", DepKind::Development)]),
497497
pkg!("bar"),
498498
pkg!("bat"),
499499
]);
500500

501-
let res = resolve(vec![dep("foo"), dep_kind("baz", Kind::Development)], &reg).unwrap();
501+
let res = resolve(
502+
vec![dep("foo"), dep_kind("baz", DepKind::Development)],
503+
&reg,
504+
)
505+
.unwrap();
502506

503507
assert_same(&res, &names(&["root", "foo", "bar", "baz", "bat"]));
504508
}
@@ -1061,7 +1065,7 @@ fn resolving_with_public_constrained_sibling() {
10611065
dep_req("backtrack_trap1", "1.0"),
10621066
dep_req("backtrack_trap2", "1.0"),
10631067
dep_req("constrained", "<=60")]),
1064-
pkg!(("bar", "1.0.0") => [dep_req_kind("constrained", ">=60", Kind::Normal, true)]),
1068+
pkg!(("bar", "1.0.0") => [dep_req_kind("constrained", ">=60", DepKind::Normal, true)]),
10651069
];
10661070
// Bump these to make the test harder, but you'll also need to
10671071
// change the version constraints on `constrained` above. To correctly

src/cargo/core/compiler/unit_dependencies.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
1818
use crate::core::compiler::Unit;
1919
use crate::core::compiler::{BuildContext, CompileKind, CompileMode};
20-
use crate::core::dependency::Kind as DepKind;
20+
use crate::core::dependency::DepKind;
2121
use crate::core::package::Downloads;
2222
use crate::core::profiles::{Profile, UnitFor};
2323
use crate::core::resolver::Resolve;

src/cargo/core/dependency.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct Inner {
3232
registry_id: Option<SourceId>,
3333
req: VersionReq,
3434
specified_req: bool,
35-
kind: Kind,
35+
kind: DepKind,
3636
only_match_name: bool,
3737
explicit_name_in_toml: Option<InternedString>,
3838

@@ -51,7 +51,7 @@ struct SerializedDependency<'a> {
5151
name: &'a str,
5252
source: SourceId,
5353
req: String,
54-
kind: Kind,
54+
kind: DepKind,
5555
rename: Option<&'a str>,
5656

5757
optional: bool,
@@ -86,7 +86,7 @@ impl ser::Serialize for Dependency {
8686
}
8787

8888
#[derive(PartialEq, Eq, Hash, Ord, PartialOrd, Clone, Debug, Copy)]
89-
pub enum Kind {
89+
pub enum DepKind {
9090
Normal,
9191
Development,
9292
Build,
@@ -138,15 +138,15 @@ this warning.
138138
}
139139
}
140140

141-
impl ser::Serialize for Kind {
141+
impl ser::Serialize for DepKind {
142142
fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
143143
where
144144
S: ser::Serializer,
145145
{
146146
match *self {
147-
Kind::Normal => None,
148-
Kind::Development => Some("dev"),
149-
Kind::Build => Some("build"),
147+
DepKind::Normal => None,
148+
DepKind::Development => Some("dev"),
149+
DepKind::Build => Some("build"),
150150
}
151151
.serialize(s)
152152
}
@@ -208,7 +208,7 @@ impl Dependency {
208208
source_id,
209209
registry_id: None,
210210
req: VersionReq::any(),
211-
kind: Kind::Normal,
211+
kind: DepKind::Normal,
212212
only_match_name: true,
213213
optional: false,
214214
public: false,
@@ -284,7 +284,7 @@ impl Dependency {
284284
self
285285
}
286286

287-
pub fn kind(&self) -> Kind {
287+
pub fn kind(&self) -> DepKind {
288288
self.inner.kind
289289
}
290290

@@ -296,7 +296,7 @@ impl Dependency {
296296
pub fn set_public(&mut self, public: bool) -> &mut Dependency {
297297
if public {
298298
// Setting 'public' only makes sense for normal dependencies
299-
assert_eq!(self.kind(), Kind::Normal);
299+
assert_eq!(self.kind(), DepKind::Normal);
300300
}
301301
Rc::make_mut(&mut self.inner).public = public;
302302
self
@@ -320,10 +320,10 @@ impl Dependency {
320320
self.inner.explicit_name_in_toml
321321
}
322322

323-
pub fn set_kind(&mut self, kind: Kind) -> &mut Dependency {
323+
pub fn set_kind(&mut self, kind: DepKind) -> &mut Dependency {
324324
if self.is_public() {
325325
// Setting 'public' only makes sense for normal dependencies
326-
assert_eq!(kind, Kind::Normal);
326+
assert_eq!(kind, DepKind::Normal);
327327
}
328328
Rc::make_mut(&mut self.inner).kind = kind;
329329
self
@@ -400,14 +400,14 @@ impl Dependency {
400400
/// Returns `false` if the dependency is only used to build the local package.
401401
pub fn is_transitive(&self) -> bool {
402402
match self.inner.kind {
403-
Kind::Normal | Kind::Build => true,
404-
Kind::Development => false,
403+
DepKind::Normal | DepKind::Build => true,
404+
DepKind::Development => false,
405405
}
406406
}
407407

408408
pub fn is_build(&self) -> bool {
409409
match self.inner.kind {
410-
Kind::Build => true,
410+
DepKind::Build => true,
411411
_ => false,
412412
}
413413
}

src/cargo/core/resolver/resolve.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::collections::{HashMap, HashSet};
44
use std::fmt;
55
use std::iter::FromIterator;
66

7-
use crate::core::dependency::Kind;
7+
use crate::core::dependency::DepKind;
88
use crate::core::{Dependency, PackageId, PackageIdSpec, Summary, Target};
99
use crate::util::errors::CargoResult;
1010
use crate::util::Graph;
@@ -87,7 +87,7 @@ impl Resolve {
8787
.edges(p)
8888
.filter(|(_, deps)| {
8989
deps.iter()
90-
.any(|d| d.kind() == Kind::Normal && d.is_public())
90+
.any(|d| d.kind() == DepKind::Normal && d.is_public())
9191
})
9292
.map(|(dep_package, _)| *dep_package)
9393
.collect::<HashSet<PackageId>>();

0 commit comments

Comments
 (0)