@@ -4,6 +4,7 @@ use std::task::Poll;
44
55use crate :: core:: { Dependency , PackageId , Registry , Summary } ;
66use crate :: sources:: source:: QueryKind ;
7+ use crate :: sources:: IndexSummary ;
78use crate :: util:: edit_distance:: edit_distance;
89use crate :: util:: { GlobalContext , OptVersionReq , VersionExt } ;
910use anyhow:: Error ;
@@ -302,6 +303,19 @@ pub(super) fn activation_error(
302303
303304 msg
304305 } else {
306+ // Maybe something is wrong with the available versions
307+ let mut version_candidates = loop {
308+ match registry. query_vec ( & new_dep, QueryKind :: AlternativeVersions ) {
309+ Poll :: Ready ( Ok ( candidates) ) => break candidates,
310+ Poll :: Ready ( Err ( e) ) => return to_resolve_err ( e) ,
311+ Poll :: Pending => match registry. block_until_ready ( ) {
312+ Ok ( ( ) ) => continue ,
313+ Err ( e) => return to_resolve_err ( e) ,
314+ } ,
315+ }
316+ } ;
317+ version_candidates. sort_unstable_by_key ( |a| a. as_summary ( ) . version ( ) . clone ( ) ) ;
318+
305319 // Maybe the user mistyped the name? Like `dep-thing` when `Dep_Thing`
306320 // was meant. So we try asking the registry for a `fuzzy` search for suggestions.
307321 let name_candidates = loop {
@@ -327,7 +341,37 @@ pub(super) fn activation_error(
327341 name_candidates. sort_by_key ( |o| o. 0 ) ;
328342
329343 let mut msg = String :: new ( ) ;
330- if !name_candidates. is_empty ( ) {
344+ if !version_candidates. is_empty ( ) {
345+ let _ = writeln ! (
346+ & mut msg,
347+ "no matching versions for `{}` found" ,
348+ dep. package_name( )
349+ ) ;
350+ for candidate in version_candidates {
351+ match candidate {
352+ IndexSummary :: Candidate ( summary) => {
353+ // HACK: If this was a real candidate, we wouldn't hit this case.
354+ // so it must be a patch which get normalized to being a candidate
355+ let _ =
356+ writeln ! ( & mut msg, " version {} is unavailable" , summary. version( ) ) ;
357+ }
358+ IndexSummary :: Yanked ( summary) => {
359+ let _ = writeln ! ( & mut msg, " version {} is yanked" , summary. version( ) ) ;
360+ }
361+ IndexSummary :: Offline ( summary) => {
362+ let _ = writeln ! ( & mut msg, " version {} is not cached" , summary. version( ) ) ;
363+ }
364+ IndexSummary :: Unsupported ( summary, schema_version) => {
365+ let _ = writeln ! (
366+ & mut msg,
367+ " version {} requires a Cargo version that supports index version {}" ,
368+ summary. version( ) ,
369+ schema_version
370+ ) ;
371+ }
372+ }
373+ }
374+ } else if !name_candidates. is_empty ( ) {
331375 let _ = writeln ! ( & mut msg, "no matching package found" , ) ;
332376 let _ = writeln ! ( & mut msg, "searched package name: `{}`" , dep. package_name( ) ) ;
333377 let mut names = name_candidates
0 commit comments