Skip to content

Commit 0802ebe

Browse files
committed
Simplify find_commandline_library
1 parent 88b25ba commit 0802ebe

File tree

1 file changed

+17
-29
lines changed

1 file changed

+17
-29
lines changed

compiler/rustc_metadata/src/locator.rs

+17-29
Original file line numberDiff line numberDiff line change
@@ -733,38 +733,26 @@ impl<'a> CrateLocator<'a> {
733733
let Some(file) = loc_orig.file_name().and_then(|s| s.to_str()) else {
734734
return Err(CrateError::ExternLocationNotFile(self.crate_name, loc_orig.clone()));
735735
};
736-
// FnMut cannot return reference to captured value, so references
737-
// must be taken outside the closure.
738-
let rlibs = &mut rlibs;
739-
let rmetas = &mut rmetas;
740-
let dylibs = &mut dylibs;
741-
let type_via_filename = (|| {
742-
if file.starts_with("lib") {
743-
if file.ends_with(".rlib") {
744-
return Some(rlibs);
745-
}
746-
if file.ends_with(".rmeta") {
747-
return Some(rmetas);
748-
}
749-
}
750-
let dll_prefix = self.target.dll_prefix.as_ref();
751-
let dll_suffix = self.target.dll_suffix.as_ref();
752-
if file.starts_with(dll_prefix) && file.ends_with(dll_suffix) {
753-
rmetas.insert(loc_canon.with_extension("rmeta"), PathKind::ExternFlag);
754-
return Some(dylibs);
755-
}
756-
None
757-
})();
758-
match type_via_filename {
759-
Some(type_via_filename) => {
760-
type_via_filename.insert(loc_canon.clone(), PathKind::ExternFlag);
736+
if file.starts_with("lib") {
737+
if file.ends_with(".rlib") {
738+
rlibs.insert(loc_canon.clone(), PathKind::ExternFlag);
739+
continue;
761740
}
762-
None => {
763-
self.crate_rejections
764-
.via_filename
765-
.push(CrateMismatch { path: loc_orig.clone(), got: String::new() });
741+
if file.ends_with(".rmeta") {
742+
rmetas.insert(loc_canon.clone(), PathKind::ExternFlag);
743+
continue;
766744
}
767745
}
746+
let dll_prefix = self.target.dll_prefix.as_ref();
747+
let dll_suffix = self.target.dll_suffix.as_ref();
748+
if file.starts_with(dll_prefix) && file.ends_with(dll_suffix) {
749+
rmetas.insert(loc_canon.with_extension("rmeta"), PathKind::ExternFlag);
750+
dylibs.insert(loc_canon.clone(), PathKind::ExternFlag);
751+
continue;
752+
}
753+
self.crate_rejections
754+
.via_filename
755+
.push(CrateMismatch { path: loc_orig.clone(), got: String::new() });
768756
}
769757

770758
// Extract the dylib/rlib/rmeta triple.

0 commit comments

Comments
 (0)