@@ -224,6 +224,7 @@ use rustc_middle::middle::cstore::{CrateSource, MetadataLoader};
224224use rustc_session:: config:: { self , CrateType } ;
225225use rustc_session:: filesearch:: { FileDoesntMatch , FileMatches , FileSearch } ;
226226use rustc_session:: search_paths:: PathKind ;
227+ use rustc_session:: utils:: CanonicalizedPath ;
227228use rustc_session:: { CrateDisambiguator , Session } ;
228229use rustc_span:: symbol:: { sym, Symbol } ;
229230use rustc_span:: Span ;
@@ -244,7 +245,7 @@ crate struct CrateLocator<'a> {
244245
245246 // Immutable per-search configuration.
246247 crate_name : Symbol ,
247- exact_paths : Vec < PathBuf > ,
248+ exact_paths : Vec < CanonicalizedPath > ,
248249 pub hash : Option < Svh > ,
249250 pub host_hash : Option < Svh > ,
250251 extra_filename : Option < & ' a str > ,
@@ -315,7 +316,7 @@ impl<'a> CrateLocator<'a> {
315316 . into_iter ( )
316317 . filter_map ( |entry| entry. files ( ) )
317318 . flatten ( )
318- . map ( PathBuf :: from )
319+ . cloned ( )
319320 . collect ( )
320321 } else {
321322 // SVH being specified means this is a transitive dependency,
@@ -664,13 +665,19 @@ impl<'a> CrateLocator<'a> {
664665 let mut rmetas = FxHashMap :: default ( ) ;
665666 let mut dylibs = FxHashMap :: default ( ) ;
666667 for loc in & self . exact_paths {
667- if !loc. exists ( ) {
668- return Err ( CrateError :: ExternLocationNotExist ( self . crate_name , loc. clone ( ) ) ) ;
668+ if !loc. canonicalized ( ) . exists ( ) {
669+ return Err ( CrateError :: ExternLocationNotExist (
670+ self . crate_name ,
671+ loc. original ( ) . clone ( ) ,
672+ ) ) ;
669673 }
670- let file = match loc. file_name ( ) . and_then ( |s| s. to_str ( ) ) {
674+ let file = match loc. original ( ) . file_name ( ) . and_then ( |s| s. to_str ( ) ) {
671675 Some ( file) => file,
672676 None => {
673- return Err ( CrateError :: ExternLocationNotFile ( self . crate_name , loc. clone ( ) ) ) ;
677+ return Err ( CrateError :: ExternLocationNotFile (
678+ self . crate_name ,
679+ loc. original ( ) . clone ( ) ,
680+ ) ) ;
674681 }
675682 } ;
676683
@@ -685,7 +692,8 @@ impl<'a> CrateLocator<'a> {
685692 // e.g. symbolic links. If we canonicalize too early, we resolve
686693 // the symlink, the file type is lost and we might treat rlibs and
687694 // rmetas as dylibs.
688- let loc_canon = fs:: canonicalize ( & loc) . unwrap_or_else ( |_| loc. clone ( ) ) ;
695+ let loc_canon = loc. canonicalized ( ) . clone ( ) ;
696+ let loc = loc. original ( ) ;
689697 if loc. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . ends_with ( ".rlib" ) {
690698 rlibs. insert ( loc_canon, PathKind :: ExternFlag ) ;
691699 } else if loc. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . ends_with ( ".rmeta" ) {
@@ -695,7 +703,7 @@ impl<'a> CrateLocator<'a> {
695703 }
696704 } else {
697705 self . rejected_via_filename
698- . push ( CrateMismatch { path : loc. clone ( ) , got : String :: new ( ) } ) ;
706+ . push ( CrateMismatch { path : loc. original ( ) . clone ( ) , got : String :: new ( ) } ) ;
699707 }
700708 }
701709
0 commit comments