@@ -195,6 +195,8 @@ pub enum IndexSummary {
195195 Candidate ( Summary ) ,
196196 /// Yanked within its registry
197197 Yanked ( Summary ) ,
198+ /// Not available as we are offline and create is not downloaded yet
199+ Offline ( Summary ) ,
198200 /// From a newer schema version and is likely incomplete or inaccurate
199201 Unsupported ( Summary , u32 ) ,
200202}
@@ -205,6 +207,7 @@ impl IndexSummary {
205207 match self {
206208 IndexSummary :: Candidate ( sum)
207209 | IndexSummary :: Yanked ( sum)
210+ | IndexSummary :: Offline ( sum)
208211 | IndexSummary :: Unsupported ( sum, _) => sum,
209212 }
210213 }
@@ -214,6 +217,7 @@ impl IndexSummary {
214217 match self {
215218 IndexSummary :: Candidate ( sum)
216219 | IndexSummary :: Yanked ( sum)
220+ | IndexSummary :: Offline ( sum)
217221 | IndexSummary :: Unsupported ( sum, _) => sum. package_id ( ) ,
218222 }
219223 }
@@ -471,6 +475,9 @@ impl<'cfg> RegistryIndex<'cfg> {
471475 ) ;
472476 None
473477 }
478+ Ok ( IndexSummary :: Offline ( _) ) => {
479+ unreachable ! ( "We do not check for off-line until later" )
480+ }
474481 Err ( e) => {
475482 info ! ( "failed to parse `{}` registry package: {}" , name, e) ;
476483 None
@@ -555,14 +562,35 @@ impl<'cfg> RegistryIndex<'cfg> {
555562 // then cargo will fail to download and an error message
556563 // indicating that the required dependency is unavailable while
557564 // offline will be displayed.
558- if ready ! ( self . query_inner_with_online( name, req, load, yanked_whitelist, f, false ) ?)
559- > 0
560- {
565+ let mut called = false ;
566+ let callback = & mut |s : IndexSummary | {
567+ if !matches ! ( & s, & IndexSummary :: Offline ( _) ) {
568+ called = true ;
569+ f ( s. as_summary ( ) . clone ( ) ) ;
570+ }
571+ } ;
572+ ready ! ( self . query_inner_with_online(
573+ name,
574+ req,
575+ load,
576+ yanked_whitelist,
577+ callback,
578+ false
579+ ) ?) ;
580+ if called {
561581 return Poll :: Ready ( Ok ( ( ) ) ) ;
562582 }
563583 }
564- self . query_inner_with_online ( name, req, load, yanked_whitelist, f, true )
565- . map_ok ( |_| ( ) )
584+ self . query_inner_with_online (
585+ name,
586+ req,
587+ load,
588+ yanked_whitelist,
589+ & mut |s| {
590+ f ( s. as_summary ( ) . clone ( ) ) ;
591+ } ,
592+ true ,
593+ )
566594 }
567595
568596 /// Inner implementation of [`Self::query_inner`]. Returns the number of
@@ -575,9 +603,9 @@ impl<'cfg> RegistryIndex<'cfg> {
575603 req : & OptVersionReq ,
576604 load : & mut dyn RegistryData ,
577605 yanked_whitelist : & HashSet < PackageId > ,
578- f : & mut dyn FnMut ( Summary ) ,
606+ f : & mut dyn FnMut ( IndexSummary ) ,
579607 online : bool ,
580- ) -> Poll < CargoResult < usize > > {
608+ ) -> Poll < CargoResult < ( ) > > {
581609 let source_id = self . source_id ;
582610
583611 let summaries = ready ! ( self . summaries( name, req, load) ) ?;
@@ -593,14 +621,19 @@ impl<'cfg> RegistryIndex<'cfg> {
593621 // does not satisfy the requirements, then resolution will
594622 // fail. Unfortunately, whether or not something is optional
595623 // is not known here.
596- . filter ( |s| ( online || load. is_crate_downloaded ( s. package_id ( ) ) ) )
624+ . map ( |s| {
625+ if online || load. is_crate_downloaded ( s. package_id ( ) ) {
626+ s. clone ( )
627+ } else {
628+ IndexSummary :: Offline ( s. as_summary ( ) . clone ( ) )
629+ }
630+ } )
597631 // Next filter out all yanked packages. Some yanked packages may
598632 // leak through if they're in a whitelist (aka if they were
599633 // previously in `Cargo.lock`
600634 . filter ( |s| {
601635 !matches ! ( s, IndexSummary :: Yanked ( _) ) || yanked_whitelist. contains ( & s. package_id ( ) )
602- } )
603- . map ( |s| s. clone ( ) ) ;
636+ } ) ;
604637
605638 // Handle `cargo update --precise` here.
606639 let precise = source_id. precise_registry_version ( name. as_str ( ) ) ;
@@ -631,12 +664,8 @@ impl<'cfg> RegistryIndex<'cfg> {
631664 None => true ,
632665 } ) ;
633666
634- let mut count = 0 ;
635- for summary in summaries {
636- f ( summary. as_summary ( ) . clone ( ) ) ;
637- count += 1 ;
638- }
639- Poll :: Ready ( Ok ( count) )
667+ summaries. for_each ( f) ;
668+ Poll :: Ready ( Ok ( ( ) ) )
640669 }
641670
642671 /// Looks into the summaries to check if a package has been yanked.
0 commit comments