66
66
//! details like invalidating caches and whatnot which are handled below, but
67
67
//! hopefully those are more obvious inline in the code itself.
68
68
69
- use crate :: core:: dependency:: Dependency ;
70
69
use crate :: core:: { PackageId , SourceId , Summary } ;
71
70
use crate :: sources:: registry:: { LoadResponse , RegistryData , RegistryPackage , INDEX_V_MAX } ;
72
71
use crate :: util:: interning:: InternedString ;
@@ -87,14 +86,14 @@ use std::task::{ready, Poll};
87
86
/// This loop tries all possible combinations of switching hyphen and underscores to find the
88
87
/// uncanonicalized one. As all stored inputs have the correct spelling, we start with the spelling
89
88
/// as-provided.
90
- struct UncanonicalizedIter < ' s > {
89
+ pub struct UncanonicalizedIter < ' s > {
91
90
input : & ' s str ,
92
91
num_hyphen_underscore : u32 ,
93
92
hyphen_combination_num : u16 ,
94
93
}
95
94
96
95
impl < ' s > UncanonicalizedIter < ' s > {
97
- fn new ( input : & ' s str ) -> Self {
96
+ pub fn new ( input : & ' s str ) -> Self {
98
97
let num_hyphen_underscore = input. chars ( ) . filter ( |& c| c == '_' || c == '-' ) . count ( ) as u32 ;
99
98
UncanonicalizedIter {
100
99
input,
@@ -267,7 +266,7 @@ impl<'cfg> RegistryIndex<'cfg> {
267
266
/// Returns the hash listed for a specified `PackageId`.
268
267
pub fn hash ( & mut self , pkg : PackageId , load : & mut dyn RegistryData ) -> Poll < CargoResult < & str > > {
269
268
let req = OptVersionReq :: exact ( pkg. version ( ) ) ;
270
- let summary = self . summaries ( pkg. name ( ) , & req, load) ?;
269
+ let summary = self . summaries ( & pkg. name ( ) , & req, load) ?;
271
270
let summary = ready ! ( summary) . next ( ) ;
272
271
Poll :: Ready ( Ok ( summary
273
272
. ok_or_else ( || internal ( format ! ( "no hash listed for {}" , pkg) ) ) ?
@@ -285,7 +284,7 @@ impl<'cfg> RegistryIndex<'cfg> {
285
284
/// though since this method is called quite a lot on null builds in Cargo.
286
285
pub fn summaries < ' a , ' b > (
287
286
& ' a mut self ,
288
- name : InternedString ,
287
+ name : & str ,
289
288
req : & ' b OptVersionReq ,
290
289
load : & mut dyn RegistryData ,
291
290
) -> Poll < CargoResult < impl Iterator < Item = & ' a IndexSummary > + ' b > >
@@ -299,6 +298,7 @@ impl<'cfg> RegistryIndex<'cfg> {
299
298
// has run previously this will parse a Cargo-specific cache file rather
300
299
// than the registry itself. In effect this is intended to be a quite
301
300
// cheap operation.
301
+ let name = InternedString :: new ( name) ;
302
302
let summaries = ready ! ( self . load_summaries( name, load) ?) ;
303
303
304
304
// Iterate over our summaries, extract all relevant ones which match our
@@ -361,45 +361,17 @@ impl<'cfg> RegistryIndex<'cfg> {
361
361
. flat_map ( |c| c. to_lowercase ( ) )
362
362
. collect :: < String > ( ) ;
363
363
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) ;
403
375
Poll :: Ready ( Ok ( self . summaries_cache . get_mut ( & name) . unwrap ( ) ) )
404
376
}
405
377
@@ -410,7 +382,8 @@ impl<'cfg> RegistryIndex<'cfg> {
410
382
411
383
pub fn query_inner (
412
384
& mut self ,
413
- dep : & Dependency ,
385
+ name : & str ,
386
+ req : & OptVersionReq ,
414
387
load : & mut dyn RegistryData ,
415
388
yanked_whitelist : & HashSet < PackageId > ,
416
389
f : & mut dyn FnMut ( Summary ) ,
@@ -426,25 +399,28 @@ impl<'cfg> RegistryIndex<'cfg> {
426
399
// then cargo will fail to download and an error message
427
400
// indicating that the required dependency is unavailable while
428
401
// 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
+ {
430
405
return Poll :: Ready ( Ok ( ( ) ) ) ;
431
406
}
432
407
}
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 )
434
409
. map_ok ( |_| ( ) )
435
410
}
436
411
437
412
fn query_inner_with_online (
438
413
& mut self ,
439
- dep : & Dependency ,
414
+ name : & str ,
415
+ req : & OptVersionReq ,
440
416
load : & mut dyn RegistryData ,
441
417
yanked_whitelist : & HashSet < PackageId > ,
442
418
f : & mut dyn FnMut ( Summary ) ,
443
419
online : bool ,
444
420
) -> Poll < CargoResult < usize > > {
445
421
let source_id = self . source_id ;
446
422
447
- let summaries = ready ! ( self . summaries( dep . package_name ( ) , dep . version_req ( ) , load) ) ?;
423
+ let summaries = ready ! ( self . summaries( name , req , load) ) ?;
448
424
449
425
let summaries = summaries
450
426
// First filter summaries for `--offline`. If we're online then
@@ -469,7 +445,6 @@ impl<'cfg> RegistryIndex<'cfg> {
469
445
// `<pkg>=<p_req>o-><f_req>` where `<pkg>` is the name of a crate on
470
446
// this source, `<p_req>` is the version installed and `<f_req> is the
471
447
// version requested (argument to `--precise`).
472
- let name = dep. package_name ( ) . as_str ( ) ;
473
448
let precise = match source_id. precise ( ) {
474
449
Some ( p) if p. starts_with ( name) && p[ name. len ( ) ..] . starts_with ( '=' ) => {
475
450
let mut vers = p[ name. len ( ) + 1 ..] . splitn ( 2 , "->" ) ;
@@ -481,7 +456,7 @@ impl<'cfg> RegistryIndex<'cfg> {
481
456
} ;
482
457
let summaries = summaries. filter ( |s| match & precise {
483
458
Some ( ( current, requested) ) => {
484
- if dep . version_req ( ) . matches ( current) {
459
+ if req . matches ( current) {
485
460
// Unfortunately crates.io allows versions to differ only
486
461
// by build metadata. This shouldn't be allowed, but since
487
462
// it is, this will honor it if requested. However, if not
@@ -521,7 +496,7 @@ impl<'cfg> RegistryIndex<'cfg> {
521
496
) -> Poll < CargoResult < bool > > {
522
497
let req = OptVersionReq :: exact ( pkg. version ( ) ) ;
523
498
let found = self
524
- . summaries ( pkg. name ( ) , & req, load)
499
+ . summaries ( & pkg. name ( ) , & req, load)
525
500
. map_ok ( |mut p| p. any ( |summary| summary. yanked ) ) ;
526
501
found
527
502
}
0 commit comments