@@ -255,10 +255,7 @@ pub(crate) struct CrateLocator<'a> {
255255 pub tuple : TargetTuple ,
256256 pub filesearch : & ' a FileSearch ,
257257 pub is_proc_macro : bool ,
258-
259258 pub path_kind : PathKind ,
260- // Mutable in-progress state or output.
261- crate_rejections : CrateRejections ,
262259}
263260
264261#[ derive( Clone , Debug ) ]
@@ -346,34 +343,30 @@ impl<'a> CrateLocator<'a> {
346343 filesearch : sess. target_filesearch ( ) ,
347344 path_kind,
348345 is_proc_macro : false ,
349- crate_rejections : CrateRejections :: default ( ) ,
350346 }
351347 }
352348
353- pub ( crate ) fn reset ( & mut self ) {
354- self . crate_rejections . via_hash . clear ( ) ;
355- self . crate_rejections . via_triple . clear ( ) ;
356- self . crate_rejections . via_kind . clear ( ) ;
357- self . crate_rejections . via_version . clear ( ) ;
358- self . crate_rejections . via_filename . clear ( ) ;
359- self . crate_rejections . via_invalid . clear ( ) ;
360- }
361-
362- pub ( crate ) fn maybe_load_library_crate ( & mut self ) -> Result < Option < Library > , CrateError > {
349+ pub ( crate ) fn maybe_load_library_crate (
350+ & self ,
351+ crate_rejections : & mut CrateRejections ,
352+ ) -> Result < Option < Library > , CrateError > {
363353 if !self . exact_paths . is_empty ( ) {
364- return self . find_commandline_library ( ) ;
354+ return self . find_commandline_library ( crate_rejections ) ;
365355 }
366356 let mut seen_paths = FxHashSet :: default ( ) ;
367357 if let Some ( extra_filename) = self . extra_filename {
368- if let library @ Some ( _) = self . find_library_crate ( extra_filename, & mut seen_paths) ? {
358+ if let library @ Some ( _) =
359+ self . find_library_crate ( crate_rejections, extra_filename, & mut seen_paths) ?
360+ {
369361 return Ok ( library) ;
370362 }
371363 }
372- self . find_library_crate ( "" , & mut seen_paths)
364+ self . find_library_crate ( crate_rejections , "" , & mut seen_paths)
373365 }
374366
375367 fn find_library_crate (
376- & mut self ,
368+ & self ,
369+ crate_rejections : & mut CrateRejections ,
377370 extra_prefix : & str ,
378371 seen_paths : & mut FxHashSet < PathBuf > ,
379372 ) -> Result < Option < Library > , CrateError > {
@@ -465,7 +458,7 @@ impl<'a> CrateLocator<'a> {
465458 . flatten ( )
466459 {
467460 for ( _, spf) in static_matches {
468- self . crate_rejections . via_kind . push ( CrateMismatch {
461+ crate_rejections. via_kind . push ( CrateMismatch {
469462 path : spf. path . to_path_buf ( ) ,
470463 got : "static" . to_string ( ) ,
471464 } ) ;
@@ -483,7 +476,9 @@ impl<'a> CrateLocator<'a> {
483476 // search is being performed for.
484477 let mut libraries = FxIndexMap :: default ( ) ;
485478 for ( _hash, ( rlibs, rmetas, dylibs, interfaces) ) in candidates {
486- if let Some ( ( svh, lib) ) = self . extract_lib ( rlibs, rmetas, dylibs, interfaces) ? {
479+ if let Some ( ( svh, lib) ) =
480+ self . extract_lib ( crate_rejections, rlibs, rmetas, dylibs, interfaces) ?
481+ {
487482 libraries. insert ( svh, lib) ;
488483 }
489484 }
@@ -512,7 +507,8 @@ impl<'a> CrateLocator<'a> {
512507 }
513508
514509 fn extract_lib (
515- & mut self ,
510+ & self ,
511+ crate_rejections : & mut CrateRejections ,
516512 rlibs : FxIndexMap < PathBuf , PathKind > ,
517513 rmetas : FxIndexMap < PathBuf , PathKind > ,
518514 dylibs : FxIndexMap < PathBuf , PathKind > ,
@@ -524,10 +520,11 @@ impl<'a> CrateLocator<'a> {
524520 // Make sure there's at most one rlib and at most one dylib.
525521 //
526522 // See comment in `extract_one` below.
527- let rmeta = self . extract_one ( rmetas, CrateFlavor :: Rmeta , & mut slot) ?;
528- let rlib = self . extract_one ( rlibs, CrateFlavor :: Rlib , & mut slot) ?;
529- let sdylib_interface = self . extract_one ( interfaces, CrateFlavor :: SDylib , & mut slot) ?;
530- let dylib = self . extract_one ( dylibs, CrateFlavor :: Dylib , & mut slot) ?;
523+ let rmeta = self . extract_one ( crate_rejections, rmetas, CrateFlavor :: Rmeta , & mut slot) ?;
524+ let rlib = self . extract_one ( crate_rejections, rlibs, CrateFlavor :: Rlib , & mut slot) ?;
525+ let sdylib_interface =
526+ self . extract_one ( crate_rejections, interfaces, CrateFlavor :: SDylib , & mut slot) ?;
527+ let dylib = self . extract_one ( crate_rejections, dylibs, CrateFlavor :: Dylib , & mut slot) ?;
531528
532529 if sdylib_interface. is_some ( ) && dylib. is_none ( ) {
533530 return Err ( CrateError :: FullMetadataNotFound ( self . crate_name , CrateFlavor :: SDylib ) ) ;
@@ -561,7 +558,8 @@ impl<'a> CrateLocator<'a> {
561558 //
562559 // The `PathBuf` in `slot` will only be used for diagnostic purposes.
563560 fn extract_one (
564- & mut self ,
561+ & self ,
562+ crate_rejections : & mut CrateRejections ,
565563 m : FxIndexMap < PathBuf , PathKind > ,
566564 flavor : CrateFlavor ,
567565 slot : & mut Option < ( Svh , MetadataBlob , PathBuf , CrateFlavor ) > ,
@@ -603,7 +601,7 @@ impl<'a> CrateLocator<'a> {
603601 Some ( self . crate_name ) ,
604602 ) {
605603 Ok ( blob) => {
606- if let Some ( h) = self . crate_matches ( & blob, & lib) {
604+ if let Some ( h) = self . crate_matches ( crate_rejections , & blob, & lib) {
607605 ( h, blob)
608606 } else {
609607 info ! ( "metadata mismatch" ) ;
@@ -618,7 +616,7 @@ impl<'a> CrateLocator<'a> {
618616 "Rejecting via version: expected {} got {}" ,
619617 expected_version, found_version
620618 ) ;
621- self . crate_rejections
619+ crate_rejections
622620 . via_version
623621 . push ( CrateMismatch { path : lib, got : found_version } ) ;
624622 continue ;
@@ -633,7 +631,7 @@ impl<'a> CrateLocator<'a> {
633631 // The file was present and created by the same compiler version, but we
634632 // couldn't load it for some reason. Give a hard error instead of silently
635633 // ignoring it, but only if we would have given an error anyway.
636- self . crate_rejections . via_invalid . push ( CrateMismatch { path : lib, got : err } ) ;
634+ crate_rejections. via_invalid . push ( CrateMismatch { path : lib, got : err } ) ;
637635 continue ;
638636 }
639637 Err ( err @ MetadataError :: NotPresent ( _) ) => {
@@ -711,7 +709,12 @@ impl<'a> CrateLocator<'a> {
711709 }
712710 }
713711
714- fn crate_matches ( & mut self , metadata : & MetadataBlob , libpath : & Path ) -> Option < Svh > {
712+ fn crate_matches (
713+ & self ,
714+ crate_rejections : & mut CrateRejections ,
715+ metadata : & MetadataBlob ,
716+ libpath : & Path ,
717+ ) -> Option < Svh > {
715718 let header = metadata. get_header ( ) ;
716719 if header. is_proc_macro_crate != self . is_proc_macro {
717720 info ! (
@@ -728,7 +731,7 @@ impl<'a> CrateLocator<'a> {
728731
729732 if header. triple != self . tuple {
730733 info ! ( "Rejecting via crate triple: expected {} got {}" , self . tuple, header. triple) ;
731- self . crate_rejections . via_triple . push ( CrateMismatch {
734+ crate_rejections. via_triple . push ( CrateMismatch {
732735 path : libpath. to_path_buf ( ) ,
733736 got : header. triple . to_string ( ) ,
734737 } ) ;
@@ -739,7 +742,7 @@ impl<'a> CrateLocator<'a> {
739742 if let Some ( expected_hash) = self . hash {
740743 if hash != expected_hash {
741744 info ! ( "Rejecting via hash: expected {} got {}" , expected_hash, hash) ;
742- self . crate_rejections
745+ crate_rejections
743746 . via_hash
744747 . push ( CrateMismatch { path : libpath. to_path_buf ( ) , got : hash. to_string ( ) } ) ;
745748 return None ;
@@ -749,7 +752,10 @@ impl<'a> CrateLocator<'a> {
749752 Some ( hash)
750753 }
751754
752- fn find_commandline_library ( & mut self ) -> Result < Option < Library > , CrateError > {
755+ fn find_commandline_library (
756+ & self ,
757+ crate_rejections : & mut CrateRejections ,
758+ ) -> Result < Option < Library > , CrateError > {
753759 // First, filter out all libraries that look suspicious. We only accept
754760 // files which actually exist that have the correct naming scheme for
755761 // rlibs/dylibs.
@@ -794,24 +800,28 @@ impl<'a> CrateLocator<'a> {
794800 dylibs. insert ( loc_canon. clone ( ) , PathKind :: ExternFlag ) ;
795801 continue ;
796802 }
797- self . crate_rejections
803+ crate_rejections
798804 . via_filename
799805 . push ( CrateMismatch { path : loc_orig. clone ( ) , got : String :: new ( ) } ) ;
800806 }
801807
802808 // Extract the dylib/rlib/rmeta triple.
803- self . extract_lib ( rlibs, rmetas, dylibs, sdylib_interfaces)
809+ self . extract_lib ( crate_rejections , rlibs, rmetas, dylibs, sdylib_interfaces)
804810 . map ( |opt| opt. map ( |( _, lib) | lib) )
805811 }
806812
807- pub ( crate ) fn into_error ( self , dep_root : Option < CratePaths > ) -> CrateError {
813+ pub ( crate ) fn into_error (
814+ self ,
815+ crate_rejections : CrateRejections ,
816+ dep_root : Option < CratePaths > ,
817+ ) -> CrateError {
808818 CrateError :: LocatorCombined ( Box :: new ( CombinedLocatorError {
809819 crate_name : self . crate_name ,
810820 dep_root,
811821 triple : self . tuple ,
812822 dll_prefix : self . target . dll_prefix . to_string ( ) ,
813823 dll_suffix : self . target . dll_suffix . to_string ( ) ,
814- crate_rejections : self . crate_rejections ,
824+ crate_rejections,
815825 } ) )
816826 }
817827}
@@ -991,7 +1001,7 @@ struct CrateMismatch {
9911001}
9921002
9931003#[ derive( Clone , Debug , Default ) ]
994- struct CrateRejections {
1004+ pub ( crate ) struct CrateRejections {
9951005 via_hash : Vec < CrateMismatch > ,
9961006 via_triple : Vec < CrateMismatch > ,
9971007 via_kind : Vec < CrateMismatch > ,
0 commit comments