@@ -364,23 +364,8 @@ fn resolve_dependency(
364
364
} ;
365
365
selected_dep = populate_dependency ( selected_dep, arg) ;
366
366
367
- let mut old_dep = get_existing_dependency ( manifest, selected_dep. toml_key ( ) , section) ?;
368
- if old_dep. is_none ( ) && selected_dep. source ( ) . is_none ( ) && selected_dep. rename ( ) . is_none ( ) {
369
- for name_permutation in [
370
- selected_dep. name . replace ( '-' , "_" ) ,
371
- selected_dep. name . replace ( '_' , "-" ) ,
372
- ] {
373
- old_dep = get_existing_dependency ( manifest, & name_permutation, section) ?;
374
- if old_dep. is_some ( ) {
375
- gctx. shell ( ) . warn ( format ! (
376
- "translating `{}` to `{}`" ,
377
- selected_dep. name, & name_permutation,
378
- ) ) ?;
379
- selected_dep. name = name_permutation;
380
- break ;
381
- }
382
- }
383
- }
367
+ let lookup = |dep_key : & _ | get_existing_dependency ( manifest, dep_key, section) ;
368
+ let old_dep = fuzzy_lookup ( & mut selected_dep, lookup, gctx) ?;
384
369
385
370
let mut dependency = if let Some ( mut old_dep) = old_dep. clone ( ) {
386
371
if old_dep. name != selected_dep. name {
@@ -488,6 +473,40 @@ fn resolve_dependency(
488
473
Ok ( dependency)
489
474
}
490
475
476
+ fn fuzzy_lookup (
477
+ dependency : & mut Dependency ,
478
+ lookup : impl Fn ( & str ) -> CargoResult < Option < Dependency > > ,
479
+ gctx : & GlobalContext ,
480
+ ) -> CargoResult < Option < Dependency > > {
481
+ if let Some ( rename) = dependency. rename ( ) {
482
+ return lookup ( rename) ;
483
+ }
484
+
485
+ for name_permutation in [
486
+ dependency. name . clone ( ) ,
487
+ dependency. name . replace ( '-' , "_" ) ,
488
+ dependency. name . replace ( '_' , "-" ) ,
489
+ ] {
490
+ let Some ( dep) = lookup ( & name_permutation) ? else {
491
+ continue ;
492
+ } ;
493
+
494
+ if dependency. name != name_permutation {
495
+ if !matches ! ( dep. source, Some ( Source :: Registry ( _) ) ) {
496
+ continue ;
497
+ }
498
+ gctx. shell ( ) . warn ( format ! (
499
+ "translating `{}` to `{}`" ,
500
+ dependency. name, & name_permutation,
501
+ ) ) ?;
502
+ dependency. name = name_permutation;
503
+ }
504
+ return Ok ( Some ( dep) ) ;
505
+ }
506
+
507
+ Ok ( None )
508
+ }
509
+
491
510
/// When { workspace = true } you cannot define other keys that configure
492
511
/// the source of the dependency such as `version`, `registry`, `registry-index`,
493
512
/// `path`, `git`, `branch`, `tag`, `rev`, or `package`. You can also not define
0 commit comments