@@ -361,7 +361,9 @@ fn resolve_dependency(
361
361
} ;
362
362
selected_dep = populate_dependency ( selected_dep, arg) ;
363
363
364
- let old_dep = get_existing_dependency ( manifest, selected_dep. toml_key ( ) , section) ?;
364
+ let lookup = |dep_key : & _ | get_existing_dependency ( manifest, dep_key, section) ;
365
+ let old_dep = fuzzy_lookup ( & mut selected_dep, lookup, gctx) ?;
366
+
365
367
let mut dependency = if let Some ( mut old_dep) = old_dep. clone ( ) {
366
368
if old_dep. name != selected_dep. name {
367
369
// Assuming most existing keys are not relevant when the package changes
@@ -383,7 +385,8 @@ fn resolve_dependency(
383
385
if dependency. source ( ) . is_none ( ) {
384
386
// Checking for a workspace dependency happens first since a member could be specified
385
387
// in the workspace dependencies table as a dependency
386
- if let Some ( _dep) = find_workspace_dep ( dependency. toml_key ( ) , ws. root_manifest ( ) ) . ok ( ) {
388
+ let lookup = |toml_key : & _ | Ok ( find_workspace_dep ( toml_key, ws. root_manifest ( ) ) . ok ( ) ) ;
389
+ if let Some ( _dep) = fuzzy_lookup ( & mut dependency, lookup, gctx) ? {
387
390
dependency = dependency. set_source ( WorkspaceSource :: new ( ) ) ;
388
391
} else if let Some ( package) = ws. members ( ) . find ( |p| p. name ( ) . as_str ( ) == dependency. name ) {
389
392
// Only special-case workspaces when the user doesn't provide any extra
@@ -449,6 +452,40 @@ fn resolve_dependency(
449
452
Ok ( dependency)
450
453
}
451
454
455
+ fn fuzzy_lookup (
456
+ dependency : & mut Dependency ,
457
+ lookup : impl Fn ( & str ) -> CargoResult < Option < Dependency > > ,
458
+ gctx : & GlobalContext ,
459
+ ) -> CargoResult < Option < Dependency > > {
460
+ if let Some ( rename) = dependency. rename ( ) {
461
+ return lookup ( rename) ;
462
+ }
463
+
464
+ for name_permutation in [
465
+ dependency. name . clone ( ) ,
466
+ dependency. name . replace ( '-' , "_" ) ,
467
+ dependency. name . replace ( '_' , "-" ) ,
468
+ ] {
469
+ let Some ( dep) = lookup ( & name_permutation) ? else {
470
+ continue ;
471
+ } ;
472
+
473
+ if dependency. name != name_permutation {
474
+ if !matches ! ( dep. source, Some ( Source :: Registry ( _) ) ) {
475
+ continue ;
476
+ }
477
+ gctx. shell ( ) . warn ( format ! (
478
+ "translating `{}` to `{}`" ,
479
+ dependency. name, & name_permutation,
480
+ ) ) ?;
481
+ dependency. name = name_permutation;
482
+ }
483
+ return Ok ( Some ( dep) ) ;
484
+ }
485
+
486
+ Ok ( None )
487
+ }
488
+
452
489
/// When { workspace = true } you cannot define other keys that configure
453
490
/// the source of the dependency such as `version`, `registry`, `registry-index`,
454
491
/// `path`, `git`, `branch`, `tag`, `rev`, or `package`. You can also not define
0 commit comments