6666//! details like invalidating caches and whatnot which are handled below, but
6767//! hopefully those are more obvious inline in the code itself.
6868
69- use crate :: core:: dependency:: Dependency ;
7069use crate :: core:: { PackageId , SourceId , Summary } ;
7170use crate :: sources:: registry:: { LoadResponse , RegistryData , RegistryPackage , INDEX_V_MAX } ;
7271use crate :: util:: interning:: InternedString ;
@@ -87,14 +86,14 @@ use std::task::{ready, Poll};
8786/// This loop tries all possible combinations of switching hyphen and underscores to find the
8887/// uncanonicalized one. As all stored inputs have the correct spelling, we start with the spelling
8988/// as-provided.
90- struct UncanonicalizedIter < ' s > {
89+ pub struct UncanonicalizedIter < ' s > {
9190 input : & ' s str ,
9291 num_hyphen_underscore : u32 ,
9392 hyphen_combination_num : u16 ,
9493}
9594
9695impl < ' s > UncanonicalizedIter < ' s > {
97- fn new ( input : & ' s str ) -> Self {
96+ pub fn new ( input : & ' s str ) -> Self {
9897 let num_hyphen_underscore = input. chars ( ) . filter ( |& c| c == '_' || c == '-' ) . count ( ) as u32 ;
9998 UncanonicalizedIter {
10099 input,
@@ -267,7 +266,7 @@ impl<'cfg> RegistryIndex<'cfg> {
267266 /// Returns the hash listed for a specified `PackageId`.
268267 pub fn hash ( & mut self , pkg : PackageId , load : & mut dyn RegistryData ) -> Poll < CargoResult < & str > > {
269268 let req = OptVersionReq :: exact ( pkg. version ( ) ) ;
270- let summary = self . summaries ( pkg. name ( ) , & req, load) ?;
269+ let summary = self . summaries ( & pkg. name ( ) , & req, load) ?;
271270 let summary = ready ! ( summary) . next ( ) ;
272271 Poll :: Ready ( Ok ( summary
273272 . ok_or_else ( || internal ( format ! ( "no hash listed for {}" , pkg) ) ) ?
@@ -285,7 +284,7 @@ impl<'cfg> RegistryIndex<'cfg> {
285284 /// though since this method is called quite a lot on null builds in Cargo.
286285 pub fn summaries < ' a , ' b > (
287286 & ' a mut self ,
288- name : InternedString ,
287+ name : & str ,
289288 req : & ' b OptVersionReq ,
290289 load : & mut dyn RegistryData ,
291290 ) -> Poll < CargoResult < impl Iterator < Item = & ' a IndexSummary > + ' b > >
@@ -299,6 +298,7 @@ impl<'cfg> RegistryIndex<'cfg> {
299298 // has run previously this will parse a Cargo-specific cache file rather
300299 // than the registry itself. In effect this is intended to be a quite
301300 // cheap operation.
301+ let name = InternedString :: new ( name) ;
302302 let summaries = ready ! ( self . load_summaries( name, load) ?) ;
303303
304304 // Iterate over our summaries, extract all relevant ones which match our
@@ -361,45 +361,17 @@ impl<'cfg> RegistryIndex<'cfg> {
361361 . flat_map ( |c| c. to_lowercase ( ) )
362362 . collect :: < String > ( ) ;
363363
364- let mut any_pending = false ;
365- // Attempt to handle misspellings by searching for a chain of related
366- // names to the original `fs_name` name. Only return summaries
367- // associated with the first hit, however. The resolver will later
368- // reject any candidates that have the wrong name, and with this it'll
369- // along the way produce helpful "did you mean?" suggestions.
370- for ( i, name_permutation) in UncanonicalizedIter :: new ( & fs_name) . take ( 1024 ) . enumerate ( ) {
371- let path = make_dep_path ( & name_permutation, false ) ;
372- let summaries = Summaries :: parse (
373- root,
374- & cache_root,
375- path. as_ref ( ) ,
376- self . source_id ,
377- load,
378- self . config ,
379- ) ?;
380- if summaries. is_pending ( ) {
381- if i == 0 {
382- // If we have not herd back about the name as requested
383- // then don't ask about other spellings yet.
384- // This prevents us spamming all the variations in the
385- // case where we have the correct spelling.
386- return Poll :: Pending ;
387- }
388- any_pending = true ;
389- }
390- if let Poll :: Ready ( Some ( summaries) ) = summaries {
391- self . summaries_cache . insert ( name, summaries) ;
392- return Poll :: Ready ( Ok ( self . summaries_cache . get_mut ( & name) . unwrap ( ) ) ) ;
393- }
394- }
395-
396- if any_pending {
397- return Poll :: Pending ;
398- }
399-
400- // If nothing was found then this crate doesn't exists, so just use an
401- // empty `Summaries` list.
402- self . summaries_cache . insert ( name, Summaries :: default ( ) ) ;
364+ let path = make_dep_path ( & fs_name, false ) ;
365+ let summaries = ready ! ( Summaries :: parse(
366+ root,
367+ & cache_root,
368+ path. as_ref( ) ,
369+ self . source_id,
370+ load,
371+ self . config,
372+ ) ) ?
373+ . unwrap_or_default ( ) ;
374+ self . summaries_cache . insert ( name, summaries) ;
403375 Poll :: Ready ( Ok ( self . summaries_cache . get_mut ( & name) . unwrap ( ) ) )
404376 }
405377
@@ -410,7 +382,8 @@ impl<'cfg> RegistryIndex<'cfg> {
410382
411383 pub fn query_inner (
412384 & mut self ,
413- dep : & Dependency ,
385+ name : & str ,
386+ req : & OptVersionReq ,
414387 load : & mut dyn RegistryData ,
415388 yanked_whitelist : & HashSet < PackageId > ,
416389 f : & mut dyn FnMut ( Summary ) ,
@@ -426,25 +399,28 @@ impl<'cfg> RegistryIndex<'cfg> {
426399 // then cargo will fail to download and an error message
427400 // indicating that the required dependency is unavailable while
428401 // offline will be displayed.
429- if ready ! ( self . query_inner_with_online( dep, load, yanked_whitelist, f, false ) ?) > 0 {
402+ if ready ! ( self . query_inner_with_online( name, req, load, yanked_whitelist, f, false ) ?)
403+ > 0
404+ {
430405 return Poll :: Ready ( Ok ( ( ) ) ) ;
431406 }
432407 }
433- self . query_inner_with_online ( dep , load, yanked_whitelist, f, true )
408+ self . query_inner_with_online ( name , req , load, yanked_whitelist, f, true )
434409 . map_ok ( |_| ( ) )
435410 }
436411
437412 fn query_inner_with_online (
438413 & mut self ,
439- dep : & Dependency ,
414+ name : & str ,
415+ req : & OptVersionReq ,
440416 load : & mut dyn RegistryData ,
441417 yanked_whitelist : & HashSet < PackageId > ,
442418 f : & mut dyn FnMut ( Summary ) ,
443419 online : bool ,
444420 ) -> Poll < CargoResult < usize > > {
445421 let source_id = self . source_id ;
446422
447- let summaries = ready ! ( self . summaries( dep . package_name ( ) , dep . version_req ( ) , load) ) ?;
423+ let summaries = ready ! ( self . summaries( name , req , load) ) ?;
448424
449425 let summaries = summaries
450426 // First filter summaries for `--offline`. If we're online then
@@ -469,7 +445,6 @@ impl<'cfg> RegistryIndex<'cfg> {
469445 // `<pkg>=<p_req>o-><f_req>` where `<pkg>` is the name of a crate on
470446 // this source, `<p_req>` is the version installed and `<f_req> is the
471447 // version requested (argument to `--precise`).
472- let name = dep. package_name ( ) . as_str ( ) ;
473448 let precise = match source_id. precise ( ) {
474449 Some ( p) if p. starts_with ( name) && p[ name. len ( ) ..] . starts_with ( '=' ) => {
475450 let mut vers = p[ name. len ( ) + 1 ..] . splitn ( 2 , "->" ) ;
@@ -481,7 +456,7 @@ impl<'cfg> RegistryIndex<'cfg> {
481456 } ;
482457 let summaries = summaries. filter ( |s| match & precise {
483458 Some ( ( current, requested) ) => {
484- if dep . version_req ( ) . matches ( current) {
459+ if req . matches ( current) {
485460 // Unfortunately crates.io allows versions to differ only
486461 // by build metadata. This shouldn't be allowed, but since
487462 // it is, this will honor it if requested. However, if not
@@ -521,7 +496,7 @@ impl<'cfg> RegistryIndex<'cfg> {
521496 ) -> Poll < CargoResult < bool > > {
522497 let req = OptVersionReq :: exact ( pkg. version ( ) ) ;
523498 let found = self
524- . summaries ( pkg. name ( ) , & req, load)
499+ . summaries ( & pkg. name ( ) , & req, load)
525500 . map_ok ( |mut p| p. any ( |summary| summary. yanked ) ) ;
526501 found
527502 }
0 commit comments