@@ -261,6 +261,7 @@ crate struct CrateLocator<'a> {
261
261
262
262
// Immutable per-search configuration.
263
263
crate_name : Symbol ,
264
+ exact_paths : Vec < PathBuf > ,
264
265
pub hash : Option < & ' a Svh > ,
265
266
pub host_hash : Option < & ' a Svh > ,
266
267
extra_filename : Option < & ' a str > ,
@@ -277,7 +278,6 @@ crate struct CrateLocator<'a> {
277
278
rejected_via_kind : Vec < CrateMismatch > ,
278
279
rejected_via_version : Vec < CrateMismatch > ,
279
280
rejected_via_filename : Vec < CrateMismatch > ,
280
- should_match_name : bool ,
281
281
}
282
282
283
283
crate struct CratePaths {
@@ -326,6 +326,15 @@ impl<'a> CrateLocator<'a> {
326
326
sess,
327
327
metadata_loader,
328
328
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
+ } ,
329
338
hash,
330
339
host_hash,
331
340
extra_filename,
@@ -348,7 +357,6 @@ impl<'a> CrateLocator<'a> {
348
357
rejected_via_kind : Vec :: new ( ) ,
349
358
rejected_via_version : Vec :: new ( ) ,
350
359
rejected_via_filename : Vec :: new ( ) ,
351
- should_match_name : true ,
352
360
}
353
361
}
354
362
@@ -361,6 +369,9 @@ impl<'a> CrateLocator<'a> {
361
369
}
362
370
363
371
crate fn maybe_load_library_crate ( & mut self ) -> Option < Library > {
372
+ if !self . exact_paths . is_empty ( ) {
373
+ return self . find_commandline_library ( ) ;
374
+ }
364
375
let mut seen_paths = FxHashSet :: default ( ) ;
365
376
match self . extra_filename {
366
377
Some ( s) => self . find_library_crate ( s, & mut seen_paths)
@@ -486,21 +497,6 @@ impl<'a> CrateLocator<'a> {
486
497
extra_prefix : & str ,
487
498
seen_paths : & mut FxHashSet < PathBuf > )
488
499
-> 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
-
504
500
let dypair = self . dylibname ( ) ;
505
501
let staticpair = self . staticlibname ( ) ;
506
502
@@ -777,7 +773,7 @@ impl<'a> CrateLocator<'a> {
777
773
}
778
774
}
779
775
780
- if self . should_match_name {
776
+ if self . exact_paths . is_empty ( ) {
781
777
if self . crate_name != root. name {
782
778
info ! ( "Rejecting via crate name" ) ;
783
779
return None ;
@@ -824,9 +820,7 @@ impl<'a> CrateLocator<'a> {
824
820
( t. options . staticlib_prefix . clone ( ) , t. options . staticlib_suffix . clone ( ) )
825
821
}
826
822
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 > {
830
824
// First, filter out all libraries that look suspicious. We only accept
831
825
// files which actually exist that have the correct naming scheme for
832
826
// rlibs/dylibs.
@@ -836,18 +830,20 @@ impl<'a> CrateLocator<'a> {
836
830
let mut rmetas = FxHashMap :: default ( ) ;
837
831
let mut dylibs = FxHashMap :: default ( ) ;
838
832
{
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| {
840
836
if !loc. exists ( ) {
841
837
sess. err ( & format ! ( "extern location for {} does not exist: {}" ,
842
- self . crate_name,
838
+ crate_name,
843
839
loc. display( ) ) ) ;
844
840
return false ;
845
841
}
846
842
let file = match loc. file_name ( ) . and_then ( |s| s. to_str ( ) ) {
847
843
Some ( file) => file,
848
844
None => {
849
845
sess. err ( & format ! ( "extern location for {} is not a file: {}" ,
850
- self . crate_name,
846
+ crate_name,
851
847
loc. display( ) ) ) ;
852
848
return false ;
853
849
}
@@ -862,8 +858,8 @@ impl<'a> CrateLocator<'a> {
862
858
}
863
859
}
864
860
865
- self . rejected_via_filename . push ( CrateMismatch {
866
- path : loc. clone ( ) ,
861
+ rejected_via_filename. push ( CrateMismatch {
862
+ path : ( * loc) . clone ( ) ,
867
863
got : String :: new ( ) ,
868
864
} ) ;
869
865
0 commit comments