Skip to content

Commit b7d4b79

Browse files
committed
Lookup translated names in workspace deps
This fixes #13702 and #10680
1 parent c1af9d7 commit b7d4b79

File tree

3 files changed

+28
-18
lines changed
  • src/cargo/ops/cargo_add
  • tests/testsuite/cargo_add

3 files changed

+28
-18
lines changed

src/cargo/ops/cargo_add/mod.rs

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -364,24 +364,28 @@ fn resolve_dependency(
364364
};
365365
selected_dep = populate_dependency(selected_dep, arg);
366366

367-
let old_dep = get_existing_dependency(manifest, selected_dep.toml_key(), section)?;
368-
let mut dependency = if let Some(mut old_dep) = old_dep.clone() {
369-
if old_dep.name != selected_dep.name {
370-
// Assuming most existing keys are not relevant when the package changes
371-
if selected_dep.optional.is_none() {
372-
selected_dep.optional = old_dep.optional;
367+
let get_dependency = |mut selected_dep: Dependency| {
368+
let old_dep = get_existing_dependency(manifest, selected_dep.toml_key(), section)?;
369+
let dependency = if let Some(mut old_dep) = old_dep.clone() {
370+
if old_dep.name != selected_dep.name {
371+
// Assuming most existing keys are not relevant when the package changes
372+
if selected_dep.optional.is_none() {
373+
selected_dep.optional = old_dep.optional;
374+
}
375+
selected_dep
376+
} else {
377+
if selected_dep.source().is_some() {
378+
// Overwrite with `crate_spec`
379+
old_dep.source = selected_dep.source;
380+
}
381+
populate_dependency(old_dep, arg)
373382
}
374-
selected_dep
375383
} else {
376-
if selected_dep.source().is_some() {
377-
// Overwrite with `crate_spec`
378-
old_dep.source = selected_dep.source;
379-
}
380-
populate_dependency(old_dep, arg)
381-
}
382-
} else {
383-
selected_dep
384+
selected_dep
385+
};
386+
anyhow::Ok((old_dep, dependency))
384387
};
388+
let (mut old_dep, mut dependency) = get_dependency(selected_dep)?;
385389

386390
if dependency.source().is_none() {
387391
// Checking for a workspace dependency happens first since a member could be specified
@@ -403,14 +407,22 @@ fn resolve_dependency(
403407
let latest =
404408
get_latest_dependency(spec, &dependency, honor_rust_version, gctx, registry)?;
405409

410+
dependency = dependency.set_source(latest.source.expect("latest always has a source"));
411+
406412
if dependency.name != latest.name {
407413
gctx.shell().warn(format!(
408414
"translating `{}` to `{}`",
409415
dependency.name, latest.name,
410416
))?;
411417
dependency.name = latest.name; // Normalize the name
418+
(old_dep, dependency) = get_dependency(dependency.clone())?;
419+
420+
// Re-check workspace dependencies table with normalized name
421+
if let Some(_dep) = find_workspace_dep(dependency.toml_key(), ws.root_manifest()).ok()
422+
{
423+
dependency = dependency.set_source(WorkspaceSource::new());
424+
}
412425
}
413-
dependency = dependency.set_source(latest.source.expect("latest always has a source"));
414426
}
415427
}
416428

tests/testsuite/cargo_add/detect_workspace_inherit_fuzzy/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use cargo_test_support::str;
77
use cargo_test_support::Project;
88

99
#[cargo_test]
10-
#[ignore]
1110
fn case() {
1211
cargo_test_support::registry::init();
1312

tests/testsuite/cargo_add/features_fuzzy/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use cargo_test_support::str;
66
use cargo_test_support::Project;
77

88
#[cargo_test]
9-
#[ignore]
109
fn case() {
1110
cargo_test_support::registry::init();
1211
cargo_test_support::registry::Package::new("your_face", "99999.0.0+my-package")

0 commit comments

Comments
 (0)