Skip to content

Commit d47c52e

Browse files
author
Jon Gjengset
committed
Prefer config [patch] over manifest [patch]
1 parent 851defd commit d47c52e

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/cargo/core/workspace.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -434,24 +434,24 @@ impl<'cfg> Workspace<'cfg> {
434434

435435
// We could just chain from_manifest and from_config,
436436
// but that's not quite right as it won't deal with overlaps.
437-
let mut combined = from_manifest.clone();
438-
for (url, cdeps) in from_config {
439-
if let Some(deps) = combined.get_mut(&url) {
440-
// We want from_manifest to take precedence for each patched name.
437+
let mut combined = from_config;
438+
for (url, deps_from_manifest) in from_manifest {
439+
if let Some(deps_from_config) = combined.get_mut(&url) {
440+
// We want from_config to take precedence for each patched name.
441441
// NOTE: This is inefficient if the number of patches is large!
442-
let mut left = cdeps.clone();
443-
for dep in &mut *deps {
444-
if let Some(i) = left.iter().position(|cdep| {
442+
let mut from_manifest_pruned = deps_from_manifest.clone();
443+
for dep_from_config in &mut *deps_from_config {
444+
if let Some(i) = from_manifest_pruned.iter().position(|dep_from_manifest| {
445445
// XXX: should this also take into account version numbers?
446-
dep.name_in_toml() == cdep.name_in_toml()
446+
dep_from_config.name_in_toml() == dep_from_manifest.name_in_toml()
447447
}) {
448-
left.swap_remove(i);
448+
from_manifest_pruned.swap_remove(i);
449449
}
450450
}
451451
// Whatever is left does not exist in manifest dependencies.
452-
deps.extend(left);
452+
deps_from_config.extend(from_manifest_pruned);
453453
} else {
454-
combined.insert(url.clone(), cdeps.clone());
454+
combined.insert(url.clone(), deps_from_manifest.clone());
455455
}
456456
}
457457
Ok(combined)

tests/testsuite/patch.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -211,14 +211,14 @@ fn from_config_precedence() {
211211
bar = "0.1.0"
212212
213213
[patch.crates-io]
214-
bar = { path = 'bar' }
214+
bar = { path = 'no-such-path' }
215215
"#,
216216
)
217217
.file(
218218
".cargo/config.toml",
219219
r#"
220220
[patch.crates-io]
221-
bar = { path = 'no-such-path' }
221+
bar = { path = 'bar' }
222222
"#,
223223
)
224224
.file("src/lib.rs", "")

0 commit comments

Comments
 (0)