Skip to content

Commit dd7b38f

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

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

compiler/rustc_metadata/src/locator.rs

+17-12
Original file line numberDiff line numberDiff line change
@@ -721,28 +721,33 @@ impl<'a> CrateLocator<'a> {
721721
return Err(CrateError::ExternLocationNotFile(self.crate_name, loc.clone()));
722722
};
723723

724-
if file.starts_with("lib") && (file.ends_with(".rlib") || file.ends_with(".rmeta"))
725-
|| file.starts_with(self.target.dll_prefix.as_ref())
726-
&& file.ends_with(self.target.dll_suffix.as_ref())
727-
{
724+
match file.starts_with("lib").then_some(()).and_then(|()| {
728725
// Note to take care and match against the non-canonicalized name:
729726
// some systems save build artifacts into content-addressed stores
730727
// that do not preserve extensions, and then link to them using
731728
// e.g. symbolic links. If we canonicalize too early, we resolve
732729
// the symlink, the file type is lost and we might treat rlibs and
733730
// rmetas as dylibs.
734-
let loc_canon = loc_canon.clone();
731+
let dll_prefix = self.target.dll_prefix.as_ref();
732+
let dll_suffix = self.target.dll_suffix.as_ref();
735733
if file.ends_with(".rlib") {
736-
rlibs.insert(loc_canon, PathKind::ExternFlag);
734+
Some(&mut rlibs)
737735
} else if file.ends_with(".rmeta") {
738-
rmetas.insert(loc_canon, PathKind::ExternFlag);
736+
Some(&mut rmetas)
737+
} else if file.starts_with(dll_prefix) && file.ends_with(dll_suffix) {
738+
Some(&mut dylibs)
739739
} else {
740-
dylibs.insert(loc_canon, PathKind::ExternFlag);
740+
None
741+
}
742+
}) {
743+
Some(dst) => {
744+
dst.insert(loc_canon.clone(), PathKind::ExternFlag);
745+
}
746+
None => {
747+
self.crate_rejections
748+
.via_filename
749+
.push(CrateMismatch { path: loc.clone(), got: String::new() });
741750
}
742-
} else {
743-
self.crate_rejections
744-
.via_filename
745-
.push(CrateMismatch { path: loc.clone(), got: String::new() });
746751
}
747752
}
748753

0 commit comments

Comments
 (0)