@@ -231,7 +231,9 @@ fn activate_deps_loop(
231
231
// to amortize the cost of the current time lookup.
232
232
ticks += 1 ;
233
233
if let Some ( config) = config {
234
- if config. shell ( ) . is_err_tty ( ) && !printed && ticks % 1000 == 0
234
+ if config. shell ( ) . is_err_tty ( )
235
+ && !printed
236
+ && ticks % 1000 == 0
235
237
&& start. elapsed ( ) - deps_time > time_to_print
236
238
{
237
239
printed = true ;
@@ -858,12 +860,14 @@ fn activation_error(
858
860
msg. push_str ( "\n versions that meet the requirements `" ) ;
859
861
msg. push_str ( & dep. version_req ( ) . to_string ( ) ) ;
860
862
msg. push_str ( "` are: " ) ;
861
- msg. push_str ( & candidates
862
- . iter ( )
863
- . map ( |v| v. summary . version ( ) )
864
- . map ( |v| v. to_string ( ) )
865
- . collect :: < Vec < _ > > ( )
866
- . join ( ", " ) ) ;
863
+ msg. push_str (
864
+ & candidates
865
+ . iter ( )
866
+ . map ( |v| v. summary . version ( ) )
867
+ . map ( |v| v. to_string ( ) )
868
+ . collect :: < Vec < _ > > ( )
869
+ . join ( ", " ) ,
870
+ ) ;
867
871
868
872
let mut conflicting_activations: Vec < _ > = conflicting_activations. iter ( ) . collect ( ) ;
869
873
conflicting_activations. sort_unstable ( ) ;
@@ -926,7 +930,7 @@ fn activation_error(
926
930
// We didn't actually find any candidates, so we need to
927
931
// give an error message that nothing was found.
928
932
//
929
- // Maybe the user mistyped the ver_req? Like `dep="2"` when `dep=".2"`
933
+ // Maybe the user mistyped the ver_req? Like `dep="2"` when `dep="0 .2"`
930
934
// was meant. So we re-query the registry with `deb="*"` so we can
931
935
// list a few versions that were actually found.
932
936
let all_req = semver:: VersionReq :: parse ( "*" ) . unwrap ( ) ;
@@ -981,26 +985,31 @@ fn activation_error(
981
985
// was meant. So we try asking the registry for a `fuzzy` search for suggestions.
982
986
let mut candidates = Vec :: new ( ) ;
983
987
if let Err ( e) = registry. query ( & new_dep, & mut |s| candidates. push ( s. name ( ) ) , true ) {
984
- return e
988
+ return e;
985
989
} ;
990
+ candidates. sort_unstable ( ) ;
991
+ candidates. dedup ( ) ;
992
+ let mut candidates: Vec < _ > = candidates
993
+ . iter ( )
994
+ . map ( |n| ( lev_distance ( & * new_dep. name ( ) , & * n) , n) )
995
+ . filter ( |& ( d, _) | d < 4 )
996
+ . collect ( ) ;
997
+ candidates. sort_by_key ( |o| o. 0 ) ;
986
998
let mut msg = format ! (
987
999
"no matching package named `{}` found\n \
988
1000
location searched: {}\n ",
989
1001
dep. name( ) ,
990
1002
dep. source_id( )
991
1003
) ;
992
1004
if !candidates. is_empty ( ) {
993
- candidates. sort_unstable ( ) ;
994
- candidates. dedup ( ) ;
995
- candidates. sort_by_key ( |o| lev_distance ( & * new_dep. name ( ) , & * o) ) ;
996
1005
let mut names = candidates
997
1006
. iter ( )
998
1007
. take ( 3 )
999
- . map ( |c| c. to_string ( ) )
1008
+ . map ( |c| c. 1 . as_str ( ) )
1000
1009
. collect :: < Vec < _ > > ( ) ;
1001
1010
1002
1011
if candidates. len ( ) > 3 {
1003
- names. push ( "..." . into ( ) ) ;
1012
+ names. push ( "..." ) ;
1004
1013
}
1005
1014
1006
1015
msg. push_str ( "did you mean: " ) ;
0 commit comments