@@ -255,11 +255,7 @@ crate struct CrateLocator<'a> {
255255 pub is_proc_macro : bool ,
256256
257257 // Mutable in-progress state or output.
258- rejected_via_hash : Vec < CrateMismatch > ,
259- rejected_via_triple : Vec < CrateMismatch > ,
260- rejected_via_kind : Vec < CrateMismatch > ,
261- rejected_via_version : Vec < CrateMismatch > ,
262- rejected_via_filename : Vec < CrateMismatch > ,
258+ crate_rejections : CrateRejections ,
263259}
264260
265261#[ derive( Clone ) ]
@@ -343,20 +339,16 @@ impl<'a> CrateLocator<'a> {
343339 sess. target_filesearch ( path_kind)
344340 } ,
345341 is_proc_macro : false ,
346- rejected_via_hash : Vec :: new ( ) ,
347- rejected_via_triple : Vec :: new ( ) ,
348- rejected_via_kind : Vec :: new ( ) ,
349- rejected_via_version : Vec :: new ( ) ,
350- rejected_via_filename : Vec :: new ( ) ,
342+ crate_rejections : CrateRejections :: default ( ) ,
351343 }
352344 }
353345
354346 crate fn reset ( & mut self ) {
355- self . rejected_via_hash . clear ( ) ;
356- self . rejected_via_triple . clear ( ) ;
357- self . rejected_via_kind . clear ( ) ;
358- self . rejected_via_version . clear ( ) ;
359- self . rejected_via_filename . clear ( ) ;
347+ self . crate_rejections . via_hash . clear ( ) ;
348+ self . crate_rejections . via_triple . clear ( ) ;
349+ self . crate_rejections . via_kind . clear ( ) ;
350+ self . crate_rejections . via_version . clear ( ) ;
351+ self . crate_rejections . via_filename . clear ( ) ;
360352 }
361353
362354 crate fn maybe_load_library_crate ( & mut self ) -> Result < Option < Library > , CrateError > {
@@ -439,7 +431,7 @@ impl<'a> CrateLocator<'a> {
439431 } ;
440432 FileMatches
441433 } ) ;
442- self . rejected_via_kind . extend ( staticlibs) ;
434+ self . crate_rejections . via_kind . extend ( staticlibs) ;
443435
444436 // We have now collected all known libraries into a set of candidates
445437 // keyed of the filename hash listed. For each filename, we also have a
@@ -610,7 +602,8 @@ impl<'a> CrateLocator<'a> {
610602 let found_version = metadata. get_rustc_version ( ) ;
611603 if found_version != rustc_version {
612604 info ! ( "Rejecting via version: expected {} got {}" , rustc_version, found_version) ;
613- self . rejected_via_version
605+ self . crate_rejections
606+ . via_version
614607 . push ( CrateMismatch { path : libpath. to_path_buf ( ) , got : found_version } ) ;
615608 return None ;
616609 }
@@ -632,7 +625,7 @@ impl<'a> CrateLocator<'a> {
632625
633626 if root. triple ( ) != & self . triple {
634627 info ! ( "Rejecting via crate triple: expected {} got {}" , self . triple, root. triple( ) ) ;
635- self . rejected_via_triple . push ( CrateMismatch {
628+ self . crate_rejections . via_triple . push ( CrateMismatch {
636629 path : libpath. to_path_buf ( ) ,
637630 got : root. triple ( ) . to_string ( ) ,
638631 } ) ;
@@ -643,7 +636,8 @@ impl<'a> CrateLocator<'a> {
643636 if let Some ( expected_hash) = self . hash {
644637 if hash != expected_hash {
645638 info ! ( "Rejecting via hash: expected {} got {}" , expected_hash, hash) ;
646- self . rejected_via_hash
639+ self . crate_rejections
640+ . via_hash
647641 . push ( CrateMismatch { path : libpath. to_path_buf ( ) , got : hash. to_string ( ) } ) ;
648642 return None ;
649643 }
@@ -697,7 +691,8 @@ impl<'a> CrateLocator<'a> {
697691 dylibs. insert ( loc_canon, PathKind :: ExternFlag ) ;
698692 }
699693 } else {
700- self . rejected_via_filename
694+ self . crate_rejections
695+ . via_filename
701696 . push ( CrateMismatch { path : loc. original ( ) . clone ( ) , got : String :: new ( ) } ) ;
702697 }
703698 }
@@ -713,11 +708,7 @@ impl<'a> CrateLocator<'a> {
713708 triple : self . triple ,
714709 dll_prefix : self . target . dll_prefix . clone ( ) ,
715710 dll_suffix : self . target . dll_suffix . clone ( ) ,
716- rejected_via_hash : self . rejected_via_hash ,
717- rejected_via_triple : self . rejected_via_triple ,
718- rejected_via_kind : self . rejected_via_kind ,
719- rejected_via_version : self . rejected_via_version ,
720- rejected_via_filename : self . rejected_via_filename ,
711+ crate_rejections : self . crate_rejections ,
721712 } )
722713 }
723714}
@@ -844,6 +835,15 @@ struct CrateMismatch {
844835 got : String ,
845836}
846837
838+ #[ derive( Clone , Default ) ]
839+ struct CrateRejections {
840+ via_hash : Vec < CrateMismatch > ,
841+ via_triple : Vec < CrateMismatch > ,
842+ via_kind : Vec < CrateMismatch > ,
843+ via_version : Vec < CrateMismatch > ,
844+ via_filename : Vec < CrateMismatch > ,
845+ }
846+
847847/// Candidate rejection reasons collected during crate search.
848848/// If no candidate is accepted, then these reasons are presented to the user,
849849/// otherwise they are ignored.
@@ -853,11 +853,7 @@ crate struct CombinedLocatorError {
853853 triple : TargetTriple ,
854854 dll_prefix : String ,
855855 dll_suffix : String ,
856- rejected_via_hash : Vec < CrateMismatch > ,
857- rejected_via_triple : Vec < CrateMismatch > ,
858- rejected_via_kind : Vec < CrateMismatch > ,
859- rejected_via_version : Vec < CrateMismatch > ,
860- rejected_via_filename : Vec < CrateMismatch > ,
856+ crate_rejections : CrateRejections ,
861857}
862858
863859crate enum CrateError {
@@ -966,7 +962,7 @@ impl CrateError {
966962 Some ( r) => format ! ( " which `{}` depends on" , r. name) ,
967963 } ;
968964 let mut msg = "the following crate versions were found:" . to_string ( ) ;
969- let mut err = if !locator. rejected_via_hash . is_empty ( ) {
965+ let mut err = if !locator. crate_rejections . via_hash . is_empty ( ) {
970966 let mut err = struct_span_err ! (
971967 sess,
972968 span,
@@ -976,7 +972,7 @@ impl CrateError {
976972 add,
977973 ) ;
978974 err. note ( "perhaps that crate needs to be recompiled?" ) ;
979- let mismatches = locator. rejected_via_hash . iter ( ) ;
975+ let mismatches = locator. crate_rejections . via_hash . iter ( ) ;
980976 for CrateMismatch { path, .. } in mismatches {
981977 msg. push_str ( & format ! ( "\n crate `{}`: {}" , crate_name, path. display( ) ) ) ;
982978 }
@@ -987,7 +983,7 @@ impl CrateError {
987983 }
988984 err. note ( & msg) ;
989985 err
990- } else if !locator. rejected_via_triple . is_empty ( ) {
986+ } else if !locator. crate_rejections . via_triple . is_empty ( ) {
991987 let mut err = struct_span_err ! (
992988 sess,
993989 span,
@@ -997,7 +993,7 @@ impl CrateError {
997993 locator. triple,
998994 add,
999995 ) ;
1000- let mismatches = locator. rejected_via_triple . iter ( ) ;
996+ let mismatches = locator. crate_rejections . via_triple . iter ( ) ;
1001997 for CrateMismatch { path, got } in mismatches {
1002998 msg. push_str ( & format ! (
1003999 "\n crate `{}`, target triple {}: {}" ,
@@ -1008,7 +1004,7 @@ impl CrateError {
10081004 }
10091005 err. note ( & msg) ;
10101006 err
1011- } else if !locator. rejected_via_kind . is_empty ( ) {
1007+ } else if !locator. crate_rejections . via_kind . is_empty ( ) {
10121008 let mut err = struct_span_err ! (
10131009 sess,
10141010 span,
@@ -1018,13 +1014,13 @@ impl CrateError {
10181014 add,
10191015 ) ;
10201016 err. help ( "please recompile that crate using --crate-type lib" ) ;
1021- let mismatches = locator. rejected_via_kind . iter ( ) ;
1017+ let mismatches = locator. crate_rejections . via_kind . iter ( ) ;
10221018 for CrateMismatch { path, .. } in mismatches {
10231019 msg. push_str ( & format ! ( "\n crate `{}`: {}" , crate_name, path. display( ) ) ) ;
10241020 }
10251021 err. note ( & msg) ;
10261022 err
1027- } else if !locator. rejected_via_version . is_empty ( ) {
1023+ } else if !locator. crate_rejections . via_version . is_empty ( ) {
10281024 let mut err = struct_span_err ! (
10291025 sess,
10301026 span,
@@ -1037,7 +1033,7 @@ impl CrateError {
10371033 "please recompile that crate using this compiler ({})" ,
10381034 rustc_version( ) ,
10391035 ) ) ;
1040- let mismatches = locator. rejected_via_version . iter ( ) ;
1036+ let mismatches = locator. crate_rejections . via_version . iter ( ) ;
10411037 for CrateMismatch { path, got } in mismatches {
10421038 msg. push_str ( & format ! (
10431039 "\n crate `{}` compiled by {}: {}" ,
@@ -1104,8 +1100,8 @@ impl CrateError {
11041100 err
11051101 } ;
11061102
1107- if !locator. rejected_via_filename . is_empty ( ) {
1108- let mismatches = locator. rejected_via_filename . iter ( ) ;
1103+ if !locator. crate_rejections . via_filename . is_empty ( ) {
1104+ let mismatches = locator. crate_rejections . via_filename . iter ( ) ;
11091105 for CrateMismatch { path, .. } in mismatches {
11101106 err. note ( & format ! (
11111107 "extern location for {} is of an unknown type: {}" ,
0 commit comments