Skip to content

Commit e69cb72

Browse files
committed
rustc_metadata: reduce repetition
1 parent f395551 commit e69cb72

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

compiler/rustc_metadata/src/locator.rs

+12-20
Original file line numberDiff line numberDiff line change
@@ -709,23 +709,16 @@ impl<'a> CrateLocator<'a> {
709709
let mut rmetas = FxIndexMap::default();
710710
let mut dylibs = FxIndexMap::default();
711711
for loc in &self.exact_paths {
712-
if !loc.canonicalized().exists() {
713-
return Err(CrateError::ExternLocationNotExist(
714-
self.crate_name,
715-
loc.original().clone(),
716-
));
712+
let loc_canon = loc.canonicalized();
713+
let loc = loc.original();
714+
if !loc_canon.exists() {
715+
return Err(CrateError::ExternLocationNotExist(self.crate_name, loc.clone()));
717716
}
718-
if !loc.original().is_file() {
719-
return Err(CrateError::ExternLocationNotFile(
720-
self.crate_name,
721-
loc.original().clone(),
722-
));
717+
if !loc.is_file() {
718+
return Err(CrateError::ExternLocationNotFile(self.crate_name, loc.clone()));
723719
}
724-
let Some(file) = loc.original().file_name().and_then(|s| s.to_str()) else {
725-
return Err(CrateError::ExternLocationNotFile(
726-
self.crate_name,
727-
loc.original().clone(),
728-
));
720+
let Some(file) = loc.file_name().and_then(|s| s.to_str()) else {
721+
return Err(CrateError::ExternLocationNotFile(self.crate_name, loc.clone()));
729722
};
730723

731724
if file.starts_with("lib") && (file.ends_with(".rlib") || file.ends_with(".rmeta"))
@@ -738,19 +731,18 @@ impl<'a> CrateLocator<'a> {
738731
// e.g. symbolic links. If we canonicalize too early, we resolve
739732
// the symlink, the file type is lost and we might treat rlibs and
740733
// 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") {
734+
let loc_canon = loc_canon.clone();
735+
if file.ends_with(".rlib") {
744736
rlibs.insert(loc_canon, PathKind::ExternFlag);
745-
} else if loc.file_name().unwrap().to_str().unwrap().ends_with(".rmeta") {
737+
} else if file.ends_with(".rmeta") {
746738
rmetas.insert(loc_canon, PathKind::ExternFlag);
747739
} else {
748740
dylibs.insert(loc_canon, PathKind::ExternFlag);
749741
}
750742
} else {
751743
self.crate_rejections
752744
.via_filename
753-
.push(CrateMismatch { path: loc.original().clone(), got: String::new() });
745+
.push(CrateMismatch { path: loc.clone(), got: String::new() });
754746
}
755747
}
756748

0 commit comments

Comments
 (0)