diff options
| author | Tamir Duberstein <tamird@gmail.com> | 2024-10-15 11:37:40 -0400 |
|---|---|---|
| committer | Tamir Duberstein <tamird@gmail.com> | 2024-10-17 11:13:28 -0400 |
| commit | 94a2be998d58d8dd05dc53568409be634a93f3a2 (patch) | |
| tree | 5df7328ef038489a0ac58a2b942516197277fce8 | |
| parent | 69be18d4e2c5783978f2c8dfcabf8a6fca5aa99c (diff) | |
| download | rust-94a2be998d58d8dd05dc53568409be634a93f3a2.tar.gz rust-94a2be998d58d8dd05dc53568409be634a93f3a2.zip | |
rustc_metadata: reduce repetition
| -rw-r--r-- | compiler/rustc_metadata/src/locator.rs | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/compiler/rustc_metadata/src/locator.rs b/compiler/rustc_metadata/src/locator.rs index 35954ea088d..a4a69ae9514 100644 --- a/compiler/rustc_metadata/src/locator.rs +++ b/compiler/rustc_metadata/src/locator.rs @@ -726,22 +726,36 @@ impl<'a> CrateLocator<'a> { let Some(file) = loc_orig.file_name().and_then(|s| s.to_str()) else { return Err(CrateError::ExternLocationNotFile(self.crate_name, loc_orig.clone())); }; - if file.starts_with("lib") && (file.ends_with(".rlib") || file.ends_with(".rmeta")) - || file.starts_with(self.target.dll_prefix.as_ref()) - && file.ends_with(self.target.dll_suffix.as_ref()) - { - let loc_canon = loc_canon.clone(); - if file.ends_with(".rlib") { - rlibs.insert(loc_canon, PathKind::ExternFlag); - } else if file.ends_with(".rmeta") { - rmetas.insert(loc_canon, PathKind::ExternFlag); - } else { - dylibs.insert(loc_canon, PathKind::ExternFlag); + // FnMut cannot return reference to captured value, so references + // must be taken outside the closure. + let rlibs = &mut rlibs; + let rmetas = &mut rmetas; + let dylibs = &mut dylibs; + let type_via_filename = (|| { + if file.starts_with("lib") { + if file.ends_with(".rlib") { + return Some(rlibs); + } + if file.ends_with(".rmeta") { + return Some(rmetas); + } + } + let dll_prefix = self.target.dll_prefix.as_ref(); + let dll_suffix = self.target.dll_suffix.as_ref(); + if file.starts_with(dll_prefix) && file.ends_with(dll_suffix) { + return Some(dylibs); + } + None + })(); + match type_via_filename { + Some(type_via_filename) => { + type_via_filename.insert(loc_canon.clone(), PathKind::ExternFlag); + } + None => { + self.crate_rejections + .via_filename + .push(CrateMismatch { path: loc_orig.clone(), got: String::new() }); } - } else { - self.crate_rejections - .via_filename - .push(CrateMismatch { path: loc_orig.clone(), got: String::new() }); } } |
