Skip to content

Commit c1b22c5

Browse files
committed
remove Candidate.
1 parent c86b834 commit c1b22c5

File tree

4 files changed

+31
-41
lines changed

4 files changed

+31
-41
lines changed

src/cargo/core/resolver/dep_cache.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::core::interning::InternedString;
1919
use crate::core::{Dependency, FeatureValue, PackageId, PackageIdSpec, Registry, Summary};
2020
use crate::util::errors::CargoResult;
2121

22-
use crate::core::resolver::types::{Candidate, ConflictReason, DepInfo, FeaturesSet};
22+
use crate::core::resolver::types::{ConflictReason, DepInfo, FeaturesSet};
2323
use crate::core::resolver::{ActivateResult, Method};
2424

2525
pub struct RegistryQueryer<'a> {
@@ -31,7 +31,7 @@ pub struct RegistryQueryer<'a> {
3131
/// specify minimum dependency versions to be used.
3232
minimal_versions: bool,
3333
/// a cache of `Candidate`s that fulfil a `Dependency`
34-
registry_cache: HashMap<Dependency, Rc<Vec<Candidate>>>,
34+
registry_cache: HashMap<Dependency, Rc<Vec<Summary>>>,
3535
/// a cache of `Dependency`s that are required for a `Summary`
3636
summary_cache: HashMap<
3737
(Option<PackageId>, Summary, Method),
@@ -73,7 +73,7 @@ impl<'a> RegistryQueryer<'a> {
7373
/// any candidates are returned which match an override then the override is
7474
/// applied by performing a second query for what the override should
7575
/// return.
76-
pub fn query(&mut self, dep: &Dependency) -> CargoResult<Rc<Vec<Candidate>>> {
76+
pub fn query(&mut self, dep: &Dependency) -> CargoResult<Rc<Vec<Summary>>> {
7777
if let Some(out) = self.registry_cache.get(dep).cloned() {
7878
return Ok(out);
7979
}
@@ -82,13 +82,11 @@ impl<'a> RegistryQueryer<'a> {
8282
self.registry.query(
8383
dep,
8484
&mut |s| {
85-
ret.push(Candidate { summary: s });
85+
ret.push(s);
8686
},
8787
false,
8888
)?;
89-
for candidate in ret.iter_mut() {
90-
let summary = &candidate.summary;
91-
89+
for summary in ret.iter_mut() {
9290
let mut potential_matches = self
9391
.replacements
9492
.iter()
@@ -168,12 +166,12 @@ impl<'a> RegistryQueryer<'a> {
168166
// prioritized summaries (those in `try_to_use`) and failing that we
169167
// list everything from the maximum version to the lowest version.
170168
ret.sort_unstable_by(|a, b| {
171-
let a_in_previous = self.try_to_use.contains(&a.summary.package_id());
172-
let b_in_previous = self.try_to_use.contains(&b.summary.package_id());
169+
let a_in_previous = self.try_to_use.contains(&a.package_id());
170+
let b_in_previous = self.try_to_use.contains(&b.package_id());
173171
let previous_cmp = a_in_previous.cmp(&b_in_previous).reverse();
174172
match previous_cmp {
175173
Ordering::Equal => {
176-
let cmp = a.summary.version().cmp(b.summary.version());
174+
let cmp = a.version().cmp(b.version());
177175
if self.minimal_versions {
178176
// Lower version ordered first.
179177
cmp

src/cargo/core/resolver/errors.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use failure::{Error, Fail};
77
use semver;
88

99
use super::context::Context;
10-
use super::types::{Candidate, ConflictMap, ConflictReason};
10+
use super::types::{ConflictMap, ConflictReason};
1111

1212
/// Error during resolution providing a path of `PackageId`s.
1313
pub struct ResolveError {
@@ -74,7 +74,7 @@ pub(super) fn activation_error(
7474
parent: &Summary,
7575
dep: &Dependency,
7676
conflicting_activations: &ConflictMap,
77-
candidates: &[Candidate],
77+
candidates: &[Summary],
7878
config: Option<&Config>,
7979
) -> ResolveError {
8080
let to_resolve_err = |err| {
@@ -101,7 +101,7 @@ pub(super) fn activation_error(
101101
msg.push_str(
102102
&candidates
103103
.iter()
104-
.map(|v| v.summary.version())
104+
.map(|v| v.version())
105105
.map(|v| v.to_string())
106106
.collect::<Vec<_>>()
107107
.join(", "),

src/cargo/core/resolver/mod.rs

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ use crate::util::profile;
6262

6363
use self::context::{Activations, Context};
6464
use self::dep_cache::RegistryQueryer;
65-
use self::types::{Candidate, ConflictMap, ConflictReason, DepsFrame};
65+
use self::types::{ConflictMap, ConflictReason, DepsFrame};
6666
use self::types::{FeaturesSet, RcVecIter, RemainingDeps, ResolverProgress};
6767

6868
pub use self::encode::{EncodableDependency, EncodablePackageId, EncodableResolve};
@@ -181,10 +181,7 @@ fn activate_deps_loop(
181181
// Activate all the initial summaries to kick off some work.
182182
for &(ref summary, ref method) in summaries {
183183
debug!("initial activation: {}", summary.package_id());
184-
let candidate = Candidate {
185-
summary: summary.clone(),
186-
};
187-
let res = activate(&mut cx, registry, None, candidate, method.clone());
184+
let res = activate(&mut cx, registry, None, summary.clone(), method.clone());
188185
match res {
189186
Ok(Some((frame, _))) => remaining_deps.push(frame),
190187
Ok(None) => (),
@@ -369,7 +366,7 @@ fn activate_deps_loop(
369366
None
370367
};
371368

372-
let pid = candidate.summary.package_id();
369+
let pid = candidate.package_id();
373370
let method = Method::Required {
374371
dev_deps: false,
375372
features: Rc::clone(&features),
@@ -381,7 +378,7 @@ fn activate_deps_loop(
381378
parent.name(),
382379
cur,
383380
dep.package_name(),
384-
candidate.summary.version()
381+
candidate.version()
385382
);
386383
let res = activate(&mut cx, registry, Some((&parent, &dep)), candidate, method);
387384

@@ -594,10 +591,10 @@ fn activate(
594591
cx: &mut Context,
595592
registry: &mut RegistryQueryer<'_>,
596593
parent: Option<(&Summary, &Dependency)>,
597-
candidate: Candidate,
594+
candidate: Summary,
598595
method: Method,
599596
) -> ActivateResult<Option<(DepsFrame, Duration)>> {
600-
let candidate_pid = candidate.summary.package_id();
597+
let candidate_pid = candidate.package_id();
601598
if let Some((parent, dep)) = parent {
602599
let parent_pid = parent.package_id();
603600
Rc::make_mut(
@@ -656,7 +653,7 @@ fn activate(
656653
}
657654
}
658655

659-
let activated = cx.flag_activated(&candidate.summary, &method)?;
656+
let activated = cx.flag_activated(&candidate, &method)?;
660657

661658
let candidate = match registry.replacement_summary(candidate_pid) {
662659
Some(replace) => {
@@ -675,7 +672,7 @@ fn activate(
675672
return Ok(None);
676673
}
677674
trace!("activating {}", candidate_pid);
678-
candidate.summary
675+
candidate
679676
}
680677
};
681678

@@ -726,13 +723,13 @@ struct BacktrackFrame {
726723
/// filtered out, and as they are filtered the causes will be added to `conflicting_prev_active`.
727724
#[derive(Clone)]
728725
struct RemainingCandidates {
729-
remaining: RcVecIter<Candidate>,
726+
remaining: RcVecIter<Summary>,
730727
// This is a inlined peekable generator
731-
has_another: Option<Candidate>,
728+
has_another: Option<Summary>,
732729
}
733730

734731
impl RemainingCandidates {
735-
fn new(candidates: &Rc<Vec<Candidate>>) -> RemainingCandidates {
732+
fn new(candidates: &Rc<Vec<Summary>>) -> RemainingCandidates {
736733
RemainingCandidates {
737734
remaining: RcVecIter::new(Rc::clone(candidates)),
738735
has_another: None,
@@ -761,14 +758,14 @@ impl RemainingCandidates {
761758
cx: &Context,
762759
dep: &Dependency,
763760
parent: PackageId,
764-
) -> Option<(Candidate, bool)> {
761+
) -> Option<(Summary, bool)> {
765762
'main: for (_, b) in self.remaining.by_ref() {
766-
let b_id = b.summary.package_id();
763+
let b_id = b.package_id();
767764
// The `links` key in the manifest dictates that there's only one
768765
// package in a dependency graph, globally, with that particular
769766
// `links` key. If this candidate links to something that's already
770767
// linked to by a different package then we've gotta skip this.
771-
if let Some(link) = b.summary.links() {
768+
if let Some(link) = b.links() {
772769
if let Some(&a) = cx.links.get(&link) {
773770
if a != b_id {
774771
conflicting_prev_active
@@ -788,7 +785,7 @@ impl RemainingCandidates {
788785
// Here we throw out our candidate if it's *compatible*, yet not
789786
// equal, to all previously activated versions.
790787
if let Some((a, _)) = cx.activations.get(&b_id.as_activations_key()) {
791-
if *a != b.summary {
788+
if *a != b {
792789
conflicting_prev_active
793790
.entry(a.package_id())
794791
.or_insert(ConflictReason::Semver);
@@ -904,7 +901,7 @@ fn generalize_conflicting(
904901
.find(
905902
dep,
906903
&|id| {
907-
if id == other.summary.package_id() {
904+
if id == other.package_id() {
908905
// we are imagining that we used other instead
909906
Some(backtrack_critical_age)
910907
} else {
@@ -913,9 +910,9 @@ fn generalize_conflicting(
913910
age < backtrack_critical_age)
914911
}
915912
},
916-
Some(other.summary.package_id()),
913+
Some(other.package_id()),
917914
)
918-
.map(|con| (other.summary.package_id(), con))
915+
.map(|con| (other.package_id(), con))
919916
})
920917
.collect::<Option<Vec<(PackageId, &ConflictMap)>>>()
921918
{
@@ -972,7 +969,7 @@ fn find_candidate(
972969
parent: &Summary,
973970
backtracked: bool,
974971
conflicting_activations: &ConflictMap,
975-
) -> Option<(Candidate, bool, BacktrackFrame)> {
972+
) -> Option<(Summary, bool, BacktrackFrame)> {
976973
// When we're calling this method we know that `parent` failed to
977974
// activate. That means that some dependency failed to get resolved for
978975
// whatever reason. Normally, that means that all of those reasons

src/cargo/core/resolver/types.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,6 @@ impl Method {
122122
}
123123
}
124124

125-
#[derive(Clone)]
126-
pub struct Candidate {
127-
pub summary: Summary,
128-
}
129-
130125
#[derive(Clone)]
131126
pub struct DepsFrame {
132127
pub parent: Summary,
@@ -230,7 +225,7 @@ impl RemainingDeps {
230225
/// Information about the dependencies for a crate, a tuple of:
231226
///
232227
/// (dependency info, candidates, features activated)
233-
pub type DepInfo = (Dependency, Rc<Vec<Candidate>>, FeaturesSet);
228+
pub type DepInfo = (Dependency, Rc<Vec<Summary>>, FeaturesSet);
234229

235230
/// All possible reasons that a package might fail to activate.
236231
///

0 commit comments

Comments
 (0)