@@ -255,10 +255,7 @@ pub(crate) struct CrateLocator<'a> {
255
255
pub tuple : TargetTuple ,
256
256
pub filesearch : & ' a FileSearch ,
257
257
pub is_proc_macro : bool ,
258
-
259
258
pub path_kind : PathKind ,
260
- // Mutable in-progress state or output.
261
- crate_rejections : CrateRejections ,
262
259
}
263
260
264
261
#[ derive( Clone , Debug ) ]
@@ -346,34 +343,30 @@ impl<'a> CrateLocator<'a> {
346
343
filesearch : sess. target_filesearch ( ) ,
347
344
path_kind,
348
345
is_proc_macro : false ,
349
- crate_rejections : CrateRejections :: default ( ) ,
350
346
}
351
347
}
352
348
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 > {
363
353
if !self . exact_paths . is_empty ( ) {
364
- return self . find_commandline_library ( ) ;
354
+ return self . find_commandline_library ( crate_rejections ) ;
365
355
}
366
356
let mut seen_paths = FxHashSet :: default ( ) ;
367
357
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
+ {
369
361
return Ok ( library) ;
370
362
}
371
363
}
372
- self . find_library_crate ( "" , & mut seen_paths)
364
+ self . find_library_crate ( crate_rejections , "" , & mut seen_paths)
373
365
}
374
366
375
367
fn find_library_crate (
376
- & mut self ,
368
+ & self ,
369
+ crate_rejections : & mut CrateRejections ,
377
370
extra_prefix : & str ,
378
371
seen_paths : & mut FxHashSet < PathBuf > ,
379
372
) -> Result < Option < Library > , CrateError > {
@@ -465,7 +458,7 @@ impl<'a> CrateLocator<'a> {
465
458
. flatten ( )
466
459
{
467
460
for ( _, spf) in static_matches {
468
- self . crate_rejections . via_kind . push ( CrateMismatch {
461
+ crate_rejections. via_kind . push ( CrateMismatch {
469
462
path : spf. path . to_path_buf ( ) ,
470
463
got : "static" . to_string ( ) ,
471
464
} ) ;
@@ -483,7 +476,9 @@ impl<'a> CrateLocator<'a> {
483
476
// search is being performed for.
484
477
let mut libraries = FxIndexMap :: default ( ) ;
485
478
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
+ {
487
482
libraries. insert ( svh, lib) ;
488
483
}
489
484
}
@@ -512,7 +507,8 @@ impl<'a> CrateLocator<'a> {
512
507
}
513
508
514
509
fn extract_lib (
515
- & mut self ,
510
+ & self ,
511
+ crate_rejections : & mut CrateRejections ,
516
512
rlibs : FxIndexMap < PathBuf , PathKind > ,
517
513
rmetas : FxIndexMap < PathBuf , PathKind > ,
518
514
dylibs : FxIndexMap < PathBuf , PathKind > ,
@@ -524,10 +520,11 @@ impl<'a> CrateLocator<'a> {
524
520
// Make sure there's at most one rlib and at most one dylib.
525
521
//
526
522
// 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) ?;
531
528
532
529
if sdylib_interface. is_some ( ) && dylib. is_none ( ) {
533
530
return Err ( CrateError :: FullMetadataNotFound ( self . crate_name , CrateFlavor :: SDylib ) ) ;
@@ -561,7 +558,8 @@ impl<'a> CrateLocator<'a> {
561
558
//
562
559
// The `PathBuf` in `slot` will only be used for diagnostic purposes.
563
560
fn extract_one (
564
- & mut self ,
561
+ & self ,
562
+ crate_rejections : & mut CrateRejections ,
565
563
m : FxIndexMap < PathBuf , PathKind > ,
566
564
flavor : CrateFlavor ,
567
565
slot : & mut Option < ( Svh , MetadataBlob , PathBuf , CrateFlavor ) > ,
@@ -603,7 +601,7 @@ impl<'a> CrateLocator<'a> {
603
601
Some ( self . crate_name ) ,
604
602
) {
605
603
Ok ( blob) => {
606
- if let Some ( h) = self . crate_matches ( & blob, & lib) {
604
+ if let Some ( h) = self . crate_matches ( crate_rejections , & blob, & lib) {
607
605
( h, blob)
608
606
} else {
609
607
info ! ( "metadata mismatch" ) ;
@@ -618,7 +616,7 @@ impl<'a> CrateLocator<'a> {
618
616
"Rejecting via version: expected {} got {}" ,
619
617
expected_version, found_version
620
618
) ;
621
- self . crate_rejections
619
+ crate_rejections
622
620
. via_version
623
621
. push ( CrateMismatch { path : lib, got : found_version } ) ;
624
622
continue ;
@@ -633,7 +631,7 @@ impl<'a> CrateLocator<'a> {
633
631
// The file was present and created by the same compiler version, but we
634
632
// couldn't load it for some reason. Give a hard error instead of silently
635
633
// 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 } ) ;
637
635
continue ;
638
636
}
639
637
Err ( err @ MetadataError :: NotPresent ( _) ) => {
@@ -711,7 +709,12 @@ impl<'a> CrateLocator<'a> {
711
709
}
712
710
}
713
711
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 > {
715
718
let header = metadata. get_header ( ) ;
716
719
if header. is_proc_macro_crate != self . is_proc_macro {
717
720
info ! (
@@ -728,7 +731,7 @@ impl<'a> CrateLocator<'a> {
728
731
729
732
if header. triple != self . tuple {
730
733
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 {
732
735
path : libpath. to_path_buf ( ) ,
733
736
got : header. triple . to_string ( ) ,
734
737
} ) ;
@@ -739,7 +742,7 @@ impl<'a> CrateLocator<'a> {
739
742
if let Some ( expected_hash) = self . hash {
740
743
if hash != expected_hash {
741
744
info ! ( "Rejecting via hash: expected {} got {}" , expected_hash, hash) ;
742
- self . crate_rejections
745
+ crate_rejections
743
746
. via_hash
744
747
. push ( CrateMismatch { path : libpath. to_path_buf ( ) , got : hash. to_string ( ) } ) ;
745
748
return None ;
@@ -749,7 +752,10 @@ impl<'a> CrateLocator<'a> {
749
752
Some ( hash)
750
753
}
751
754
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 > {
753
759
// First, filter out all libraries that look suspicious. We only accept
754
760
// files which actually exist that have the correct naming scheme for
755
761
// rlibs/dylibs.
@@ -794,24 +800,28 @@ impl<'a> CrateLocator<'a> {
794
800
dylibs. insert ( loc_canon. clone ( ) , PathKind :: ExternFlag ) ;
795
801
continue ;
796
802
}
797
- self . crate_rejections
803
+ crate_rejections
798
804
. via_filename
799
805
. push ( CrateMismatch { path : loc_orig. clone ( ) , got : String :: new ( ) } ) ;
800
806
}
801
807
802
808
// 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)
804
810
. map ( |opt| opt. map ( |( _, lib) | lib) )
805
811
}
806
812
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 {
808
818
CrateError :: LocatorCombined ( Box :: new ( CombinedLocatorError {
809
819
crate_name : self . crate_name ,
810
820
dep_root,
811
821
triple : self . tuple ,
812
822
dll_prefix : self . target . dll_prefix . to_string ( ) ,
813
823
dll_suffix : self . target . dll_suffix . to_string ( ) ,
814
- crate_rejections : self . crate_rejections ,
824
+ crate_rejections,
815
825
} ) )
816
826
}
817
827
}
@@ -991,7 +1001,7 @@ struct CrateMismatch {
991
1001
}
992
1002
993
1003
#[ derive( Clone , Debug , Default ) ]
994
- struct CrateRejections {
1004
+ pub ( crate ) struct CrateRejections {
995
1005
via_hash : Vec < CrateMismatch > ,
996
1006
via_triple : Vec < CrateMismatch > ,
997
1007
via_kind : Vec < CrateMismatch > ,
0 commit comments