@@ -364,24 +364,28 @@ fn resolve_dependency(
364
364
} ;
365
365
selected_dep = populate_dependency ( selected_dep, arg) ;
366
366
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)
373
382
}
374
- selected_dep
375
383
} 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) )
384
387
} ;
388
+ let ( mut old_dep, mut dependency) = get_dependency ( selected_dep) ?;
385
389
386
390
if dependency. source ( ) . is_none ( ) {
387
391
// Checking for a workspace dependency happens first since a member could be specified
@@ -403,14 +407,22 @@ fn resolve_dependency(
403
407
let latest =
404
408
get_latest_dependency ( spec, & dependency, honor_rust_version, gctx, registry) ?;
405
409
410
+ dependency = dependency. set_source ( latest. source . expect ( "latest always has a source" ) ) ;
411
+
406
412
if dependency. name != latest. name {
407
413
gctx. shell ( ) . warn ( format ! (
408
414
"translating `{}` to `{}`" ,
409
415
dependency. name, latest. name,
410
416
) ) ?;
411
417
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
+ }
412
425
}
413
- dependency = dependency. set_source ( latest. source . expect ( "latest always has a source" ) ) ;
414
426
}
415
427
}
416
428
0 commit comments