Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Eh2406 committed Sep 14, 2018
1 parent 2b1f093 commit 9b2295d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 25 deletions.
14 changes: 10 additions & 4 deletions src/cargo/core/resolver/conflict_cache.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::collections::{HashMap, HashSet};

use core::{Dependency, PackageId};
use core::resolver::Context;
use super::types::ConflictReason;
use core::resolver::Context;
use core::{Dependency, PackageId};

pub(super) struct ConflictCache {
// `con_from_dep` is a cache of the reasons for each time we
Expand Down Expand Up @@ -77,11 +77,17 @@ impl ConflictCache {
/// `dep` is known to be unresolvable if
/// all the `PackageId` entries are activated
pub fn insert(&mut self, dep: &Dependency, con: &HashMap<PackageId, ConflictReason>) {
let past = self.con_from_dep
let past = self
.con_from_dep
.entry(dep.clone())
.or_insert_with(Vec::new);
if !past.contains(con) {
trace!("{} = \"{}\" adding a skip {:?}", dep.package_name(), dep.version_req(), con);
trace!(
"{} = \"{}\" adding a skip {:?}",
dep.package_name(),
dep.version_req(),
con
);
past.push(con.clone());
for c in con.keys() {
self.dep_from_pid
Expand Down
43 changes: 27 additions & 16 deletions src/cargo/core/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,12 @@ fn activate_deps_loop(
// It's our job here to backtrack, if possible, and find a
// different candidate to activate. If we can't find any
// candidates whatsoever then it's time to bail entirely.
trace!("{}[{}]>{} -- no candidates", parent.name(), cur, dep.package_name());
trace!(
"{}[{}]>{} -- no candidates",
parent.name(),
cur,
dep.package_name()
);

// Use our list of `conflicting_activations` to add to our
// global list of past conflicting activations, effectively
Expand All @@ -325,7 +330,12 @@ fn activate_deps_loop(
past_conflicting_activations.insert(&dep, &conflicting_activations);
}

match find_candidate(&mut backtrack_stack, &parent, backtracked, &conflicting_activations) {
match find_candidate(
&mut backtrack_stack,
&parent,
backtracked,
&conflicting_activations,
) {
Some((candidate, has_another, frame)) => {
// Reset all of our local variables used with the
// contents of `frame` to complete our backtrack.
Expand Down Expand Up @@ -432,8 +442,7 @@ fn activate_deps_loop(
.clone()
.filter_map(|(_, (ref new_dep, _, _))| {
past_conflicting_activations.conflicting(&cx, new_dep)
})
.next()
}).next()
{
// If one of our deps is known unresolvable
// then we will not succeed.
Expand Down Expand Up @@ -467,18 +476,14 @@ fn activate_deps_loop(
.iter()
.flat_map(|other| other.flatten())
// for deps related to us
.filter(|&(_, ref other_dep)|
known_related_bad_deps.contains(other_dep))
.filter_map(|(other_parent, other_dep)| {
.filter(|&(_, ref other_dep)| {
known_related_bad_deps.contains(other_dep)
}).filter_map(|(other_parent, other_dep)| {
past_conflicting_activations
.find_conflicting(
&cx,
&other_dep,
|con| con.contains_key(&pid)
)
.map(|con| (other_parent, con))
})
.next()
.find_conflicting(&cx, &other_dep, |con| {
con.contains_key(&pid)
}).map(|con| (other_parent, con))
}).next()
{
let rel = conflict.get(&pid).unwrap().clone();

Expand Down Expand Up @@ -837,7 +842,13 @@ fn find_candidate(
.context_backup
.is_conflicting(Some(parent.package_id()), conflicting_activations)
{
trace!("{} = \"{}\" skip as not solving {}: {:?}", frame.dep.package_name(), frame.dep.version_req(), parent.package_id(), conflicting_activations);
trace!(
"{} = \"{}\" skip as not solving {}: {:?}",
frame.dep.package_name(),
frame.dep.version_req(),
parent.package_id(),
conflicting_activations
);
continue;
}
}
Expand Down
23 changes: 18 additions & 5 deletions tests/testsuite/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,12 @@ fn resolving_with_constrained_sibling_transitive_dep_effects() {
}

#[test]
fn dont_yet_know_the_problem() {
fn incomplete_information_skiping() {
// When backtracking due to a failed dependency, if Cargo is
// trying to be clever and skip irrelevant dependencies, care must
// be taken to not miss the transitive effects of alternatives.
// Fuzzing discovered that for some reason cargo was skiping based
// on incomplete information in the following case:
// minimized bug found in:
// https://github.com/rust-lang/cargo/commit/003c29b0c71e5ea28fbe8e72c148c755c9f3f8d9
let input = vec![
Expand Down Expand Up @@ -1007,10 +1012,13 @@ fn dont_yet_know_the_problem() {
assert!(resolve(&pkg_id("root"), vec![dep("g")], &new_reg).is_ok());
}


#[test]
fn dont_yet_know_the_problem_2() {
// minimized bug found in:
fn incomplete_information_skiping_2() {
// When backtracking due to a failed dependency, if Cargo is
// trying to be clever and skip irrelevant dependencies, care must
// be taken to not miss the transitive effects of alternatives.
// Fuzzing discovered that for some reason cargo was skiping based
// on incomplete information in the following case:
// https://github.com/rust-lang/cargo/commit/003c29b0c71e5ea28fbe8e72c148c755c9f3f8d9
let input = vec![
pkg!(("b", "3.8.10")),
Expand Down Expand Up @@ -1074,7 +1082,12 @@ fn dont_yet_know_the_problem_2() {
}

#[test]
fn dont_yet_know_the_problem_3() {
fn incomplete_information_skiping_3() {
// When backtracking due to a failed dependency, if Cargo is
// trying to be clever and skip irrelevant dependencies, care must
// be taken to not miss the transitive effects of alternatives.
// Fuzzing discovered that for some reason cargo was skiping based
// on incomplete information in the following case:
// minimized bug found in:
// https://github.com/rust-lang/cargo/commit/003c29b0c71e5ea28fbe8e72c148c755c9f3f8d9
let input = vec![
Expand Down

0 comments on commit 9b2295d

Please sign in to comment.