From b27debce914635bc155fbe4465af92d06a64d7da Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 30 Aug 2023 13:12:52 -0500 Subject: [PATCH] fix(resolver): Make resolver behavior independent or package order This address one of the problems mentioned in #12599 --- src/cargo/ops/resolve.rs | 10 +++++++--- tests/testsuite/update.rs | 7 ++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/cargo/ops/resolve.rs b/src/cargo/ops/resolve.rs index d528e8a04417..473ec6d40530 100644 --- a/src/cargo/ops/resolve.rs +++ b/src/cargo/ops/resolve.rs @@ -642,15 +642,19 @@ fn register_previous_locks( // if they changed. let mut avoid_locking = HashSet::new(); registry.add_to_yanked_whitelist(resolve.iter().filter(keep)); + // We must check `path_pkg` first so we don't recursively walk them via `add_deps` for node in resolve.iter() { - if !keep(&node) { - add_deps(resolve, node, &mut avoid_locking); - } else if let Some(pkg) = path_pkg(node.source_id()) { + if let Some(pkg) = path_pkg(node.source_id()) { if pkg.package_id() != node { avoid_locking.insert(node); } } } + for node in resolve.iter() { + if !keep(&node) { + add_deps(resolve, node, &mut avoid_locking); + } + } // Ok, but the above loop isn't the entire story! Updates to the dependency // graph can come from two locations, the `cargo update` command or diff --git a/tests/testsuite/update.rs b/tests/testsuite/update.rs index 0f2de1b76d0e..3ded6d65937a 100644 --- a/tests/testsuite/update.rs +++ b/tests/testsuite/update.rs @@ -954,14 +954,11 @@ rustdns.workspace = true p.change_file("Cargo.toml", &workspace_toml.replace("2.29.8", "2.29.81")); p.cargo("update -p rootcrate") - .with_stderr(&format!( + .with_stderr( "\ -[UPDATING] git repository `{}` [UPDATING] rootcrate v2.29.8 ([CWD]/rootcrate) -> v2.29.81 -[UPDATING] rustdns v0.5.0 ([..]) -> [..] [UPDATING] subcrate v2.29.8 ([CWD]/subcrate) -> v2.29.81", - git_project.url(), - )) + ) .run(); }