Skip to content

Commit ed09ea2

Browse files
committed
disable back jumping on pub dep error
1 parent 38c5819 commit ed09ea2

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

src/cargo/core/resolver/conflict_cache.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ impl ConflictCache {
173173
/// `dep` is known to be unresolvable if
174174
/// all the `PackageId` entries are activated.
175175
pub fn insert(&mut self, dep: &Dependency, con: &BTreeMap<PackageId, ConflictReason>) {
176+
if con.values().any(|c| *c == ConflictReason::PublicDependency) {
177+
// TODO: needs more info for back jumping
178+
// for now refuse to cache it.
179+
return;
180+
}
176181
self.con_from_dep
177182
.entry(dep.clone())
178183
.or_insert_with(|| ConflictStoreTrie::Node(BTreeMap::new()))

src/cargo/core/resolver/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ impl RemainingCandidates {
782782
// TODO: dont look at the same thing more then once
783783
if let Some(o) = cx.public_dependency.get(&p).and_then(|x| x.get(&t.name())) {
784784
if o.0 != t {
785-
// TODO: conflicting_prev_active
785+
conflicting_prev_active.insert(p, ConflictReason::PublicDependency);
786786
continue 'main;
787787
}
788788
}
@@ -868,6 +868,9 @@ fn find_candidate(
868868
// make any progress. As a result if we hit this condition we can
869869
// completely skip this backtrack frame and move on to the next.
870870
if !backtracked
871+
&& !conflicting_activations
872+
.values()
873+
.any(|c| *c == ConflictReason::PublicDependency)
871874
&& frame
872875
.context
873876
.is_conflicting(Some(parent.package_id()), conflicting_activations)

src/cargo/core/resolver/types.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,11 @@ pub enum ConflictReason {
402402
/// candidate. For example we tried to activate feature `foo` but the
403403
/// candidate we're activating didn't actually have the feature `foo`.
404404
MissingFeatures(String),
405+
406+
// TODO: needs more info for errors maneges
407+
// TODO: needs more info for back jumping
408+
/// pub dep errore
409+
PublicDependency,
405410
}
406411

407412
impl ConflictReason {

tests/testsuite/resolve.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,43 @@ fn public_dependency_filling_in_and_update() {
328328
);
329329
}
330330

331+
#[test]
332+
fn public_dependency_skiping() {
333+
// When backtracking due to a failed dependency, if Cargo is
334+
// trying to be clever and skip irrelevant dependencies, care must
335+
// the effects of pub dep must be accounted for.
336+
let input = vec![
337+
pkg!(("a", "0.2.0")),
338+
pkg!(("a", "2.0.0")),
339+
pkg!(("b", "0.0.0") => [dep("bad")]),
340+
pkg!(("b", "0.2.1") => [dep_req_kind("a", "0.2.0", Kind::Normal, true)]),
341+
pkg!("c" => [dep("a"),dep("b")]),
342+
];
343+
let reg = registry(input.clone());
344+
345+
resolve(&pkg_id("root"), vec![dep("c")], &reg).unwrap();
346+
}
347+
348+
#[test]
349+
fn public_dependency_skiping_in_backtracking() {
350+
// When backtracking due to a failed dependency, if Cargo is
351+
// trying to be clever and skip irrelevant dependencies, care must
352+
// the effects of pub dep must be accounted for.
353+
let input = vec![
354+
pkg!(("A", "0.0.0") => [dep("bad")]),
355+
pkg!(("A", "0.0.1") => [dep("bad")]),
356+
pkg!(("A", "0.0.2") => [dep("bad")]),
357+
pkg!(("A", "0.0.3") => [dep("bad")]),
358+
pkg!(("A", "0.0.4")),
359+
pkg!(("A", "0.0.5")),
360+
pkg!("B" => [dep_req_kind("A", ">= 0.0.3", Kind::Normal, true)]),
361+
pkg!("C" => [dep_req("A", "<= 0.0.4"), dep("B")]),
362+
];
363+
let reg = registry(input.clone());
364+
365+
resolve(&pkg_id("root"), vec![dep("C")], &reg).unwrap();
366+
}
367+
331368
#[test]
332369
#[should_panic(expected = "assertion failed: !name.is_empty()")]
333370
fn test_dependency_with_empty_name() {

0 commit comments

Comments
 (0)