Skip to content

Commit 69be18d

Browse files
committed
rustc_metadata: reduce repetition
1 parent f395551 commit 69be18d

1 file changed

Lines changed: 18 additions & 27 deletions

File tree

‎compiler/rustc_metadata/src/locator.rs‎

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -709,48 +709,39 @@ impl<'a> CrateLocator<'a> {
709709
letmut rmetas = FxIndexMap::default();
710710
letmut dylibs = FxIndexMap::default();
711711
for loc in&self.exact_paths{
712-
if !loc.canonicalized().exists(){
713-
returnErr(CrateError::ExternLocationNotExist(
714-
self.crate_name,
715-
loc.original().clone(),
716-
));
712+
let loc_canon = loc.canonicalized();
713+
let loc_orig = loc.original();
714+
if !loc_canon.exists(){
715+
returnErr(CrateError::ExternLocationNotExist(self.crate_name, loc_orig.clone()));
717716
}
718-
if !loc.original().is_file(){
719-
returnErr(CrateError::ExternLocationNotFile(
720-
self.crate_name,
721-
loc.original().clone(),
722-
));
717+
if !loc_orig.is_file(){
718+
returnErr(CrateError::ExternLocationNotFile(self.crate_name, loc_orig.clone()));
723719
}
724-
letSome(file) = loc.original().file_name().and_then(|s| s.to_str())else{
725-
returnErr(CrateError::ExternLocationNotFile(
726-
self.crate_name,
727-
loc.original().clone(),
728-
));
720+
// Note to take care and match against the non-canonicalized name:
721+
// some systems save build artifacts into content-addressed stores
722+
// that do not preserve extensions, and then link to them using
723+
// e.g. symbolic links. If we canonicalize too early, we resolve
724+
// the symlink, the file type is lost and we might treat rlibs and
725+
// rmetas as dylibs.
726+
letSome(file) = loc_orig.file_name().and_then(|s| s.to_str())else{
727+
returnErr(CrateError::ExternLocationNotFile(self.crate_name, loc_orig.clone()));
729728
};
730-
731729
if file.starts_with("lib") && (file.ends_with(".rlib") || file.ends_with(".rmeta"))
732730
|| file.starts_with(self.target.dll_prefix.as_ref())
733731
&& file.ends_with(self.target.dll_suffix.as_ref())
734732
{
735-
// Note to take care and match against the non-canonicalized name:
736-
// some systems save build artifacts into content-addressed stores
737-
// that do not preserve extensions, and then link to them using
738-
// e.g. symbolic links. If we canonicalize too early, we resolve
739-
// the symlink, the file type is lost and we might treat rlibs and
740-
// rmetas as dylibs.
741-
let loc_canon = loc.canonicalized().clone();
742-
let loc = loc.original();
743-
if loc.file_name().unwrap().to_str().unwrap().ends_with(".rlib"){
733+
let loc_canon = loc_canon.clone();
734+
if file.ends_with(".rlib"){
744735
rlibs.insert(loc_canon,PathKind::ExternFlag);
745-
}elseifloc.file_name().unwrap().to_str().unwrap().ends_with(".rmeta"){
736+
}elseiffile.ends_with(".rmeta"){
746737
rmetas.insert(loc_canon,PathKind::ExternFlag);
747738
}else{
748739
dylibs.insert(loc_canon,PathKind::ExternFlag);
749740
}
750741
}else{
751742
self.crate_rejections
752743
.via_filename
753-
.push(CrateMismatch{path:loc.original().clone(),got:String::new()});
744+
.push(CrateMismatch{path:loc_orig.clone(),got:String::new()});
754745
}
755746
}
756747

0 commit comments

Comments
 (0)