@@ -261,6 +261,7 @@ crate struct CrateLocator<'a> {
261261
262262 // Immutable per-search configuration.
263263 crate_name : Symbol ,
264+ exact_paths : Vec < PathBuf > ,
264265 pub hash : Option < & ' a Svh > ,
265266 pub host_hash : Option < & ' a Svh > ,
266267 extra_filename : Option < & ' a str > ,
@@ -277,7 +278,6 @@ crate struct CrateLocator<'a> {
277278 rejected_via_kind : Vec < CrateMismatch > ,
278279 rejected_via_version : Vec < CrateMismatch > ,
279280 rejected_via_filename : Vec < CrateMismatch > ,
280- should_match_name : bool ,
281281}
282282
283283crate struct CratePaths {
@@ -326,6 +326,15 @@ impl<'a> CrateLocator<'a> {
326326 sess,
327327 metadata_loader,
328328 crate_name,
329+ exact_paths : if hash. is_none ( ) {
330+ sess. opts . externs . get ( & crate_name. as_str ( ) ) . into_iter ( )
331+ . flat_map ( |entry| entry. locations . iter ( ) )
332+ . filter_map ( |location| location. clone ( ) . map ( PathBuf :: from) ) . collect ( )
333+ } else {
334+ // SVH being specified means this is a transitive dependency,
335+ // so `--extern` options do not apply.
336+ Vec :: new ( )
337+ } ,
329338 hash,
330339 host_hash,
331340 extra_filename,
@@ -348,7 +357,6 @@ impl<'a> CrateLocator<'a> {
348357 rejected_via_kind : Vec :: new ( ) ,
349358 rejected_via_version : Vec :: new ( ) ,
350359 rejected_via_filename : Vec :: new ( ) ,
351- should_match_name : true ,
352360 }
353361 }
354362
@@ -361,6 +369,9 @@ impl<'a> CrateLocator<'a> {
361369 }
362370
363371 crate fn maybe_load_library_crate ( & mut self ) -> Option < Library > {
372+ if !self . exact_paths . is_empty ( ) {
373+ return self . find_commandline_library ( ) ;
374+ }
364375 let mut seen_paths = FxHashSet :: default ( ) ;
365376 match self . extra_filename {
366377 Some ( s) => self . find_library_crate ( s, & mut seen_paths)
@@ -486,21 +497,6 @@ impl<'a> CrateLocator<'a> {
486497 extra_prefix : & str ,
487498 seen_paths : & mut FxHashSet < PathBuf > )
488499 -> Option < Library > {
489- // If an SVH is specified, then this is a transitive dependency that
490- // must be loaded via -L plus some filtering.
491- if self . hash . is_none ( ) {
492- self . should_match_name = false ;
493- if let Some ( entry) = self . sess . opts . externs . get ( & self . crate_name . as_str ( ) ) {
494- // Only use `--extern crate_name=path` here, not `--extern crate_name`.
495- if entry. locations . iter ( ) . any ( |l| l. is_some ( ) ) {
496- return self . find_commandline_library (
497- entry. locations . iter ( ) . filter_map ( |l| l. as_ref ( ) ) ,
498- ) ;
499- }
500- }
501- self . should_match_name = true ;
502- }
503-
504500 let dypair = self . dylibname ( ) ;
505501 let staticpair = self . staticlibname ( ) ;
506502
@@ -777,7 +773,7 @@ impl<'a> CrateLocator<'a> {
777773 }
778774 }
779775
780- if self . should_match_name {
776+ if self . exact_paths . is_empty ( ) {
781777 if self . crate_name != root. name {
782778 info ! ( "Rejecting via crate name" ) ;
783779 return None ;
@@ -824,9 +820,7 @@ impl<'a> CrateLocator<'a> {
824820 ( t. options . staticlib_prefix . clone ( ) , t. options . staticlib_suffix . clone ( ) )
825821 }
826822
827- fn find_commandline_library < ' b , LOCS > ( & mut self , locs : LOCS ) -> Option < Library >
828- where LOCS : Iterator < Item = & ' b String >
829- {
823+ fn find_commandline_library ( & mut self ) -> Option < Library > {
830824 // First, filter out all libraries that look suspicious. We only accept
831825 // files which actually exist that have the correct naming scheme for
832826 // rlibs/dylibs.
@@ -836,18 +830,20 @@ impl<'a> CrateLocator<'a> {
836830 let mut rmetas = FxHashMap :: default ( ) ;
837831 let mut dylibs = FxHashMap :: default ( ) ;
838832 {
839- let locs = locs. map ( |l| PathBuf :: from ( l) ) . filter ( |loc| {
833+ let crate_name = self . crate_name ;
834+ let rejected_via_filename = & mut self . rejected_via_filename ;
835+ let locs = self . exact_paths . iter ( ) . filter ( |loc| {
840836 if !loc. exists ( ) {
841837 sess. err ( & format ! ( "extern location for {} does not exist: {}" ,
842- self . crate_name,
838+ crate_name,
843839 loc. display( ) ) ) ;
844840 return false ;
845841 }
846842 let file = match loc. file_name ( ) . and_then ( |s| s. to_str ( ) ) {
847843 Some ( file) => file,
848844 None => {
849845 sess. err ( & format ! ( "extern location for {} is not a file: {}" ,
850- self . crate_name,
846+ crate_name,
851847 loc. display( ) ) ) ;
852848 return false ;
853849 }
@@ -862,8 +858,8 @@ impl<'a> CrateLocator<'a> {
862858 }
863859 }
864860
865- self . rejected_via_filename . push ( CrateMismatch {
866- path : loc. clone ( ) ,
861+ rejected_via_filename. push ( CrateMismatch {
862+ path : ( * loc) . clone ( ) ,
867863 got : String :: new ( ) ,
868864 } ) ;
869865
0 commit comments