diff options
| author | Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> | 2024-06-06 21:50:46 +0200 |
|---|---|---|
| committer | Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> | 2024-06-06 21:53:29 +0200 |
| commit | 4c2b21a2eff18212ae8363fd993d8a56d7ebfe83 (patch) | |
| tree | 87b422254b3c605f807da806279c0e26ee07871d | |
| parent | 3a02cdb54fc4e7439d2fec5562052ddee746c7fa (diff) | |
| download | rust-4c2b21a2eff18212ae8363fd993d8a56d7ebfe83.tar.gz rust-4c2b21a2eff18212ae8363fd993d8a56d7ebfe83.zip | |
Simplify string operations in crate loader
| -rw-r--r-- | compiler/rustc_metadata/src/locator.rs | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/compiler/rustc_metadata/src/locator.rs b/compiler/rustc_metadata/src/locator.rs index 861c4d42189..90fe52a3438 100644 --- a/compiler/rustc_metadata/src/locator.rs +++ b/compiler/rustc_metadata/src/locator.rs @@ -414,12 +414,18 @@ impl<'a> CrateLocator<'a> { debug!("testing {}", spf.path.display()); let f = &spf.file_name_str; - let (hash, kind) = if f.starts_with(rlib_prefix) && f.ends_with(rlib_suffix) { - (&f[rlib_prefix.len()..(f.len() - rlib_suffix.len())], CrateFlavor::Rlib) - } else if f.starts_with(rmeta_prefix) && f.ends_with(rmeta_suffix) { - (&f[rmeta_prefix.len()..(f.len() - rmeta_suffix.len())], CrateFlavor::Rmeta) - } else if f.starts_with(dylib_prefix) && f.ends_with(dylib_suffix.as_ref()) { - (&f[dylib_prefix.len()..(f.len() - dylib_suffix.len())], CrateFlavor::Dylib) + let (hash, kind) = if let Some(f) = f.strip_prefix(rlib_prefix) + && let Some(f) = f.strip_suffix(rlib_suffix) + { + (f, CrateFlavor::Rlib) + } else if let Some(f) = f.strip_prefix(rmeta_prefix) + && let Some(f) = f.strip_suffix(rmeta_suffix) + { + (f, CrateFlavor::Rmeta) + } else if let Some(f) = f.strip_prefix(dylib_prefix) + && let Some(f) = f.strip_suffix(dylib_suffix.as_ref()) + { + (f, CrateFlavor::Dylib) } else { if f.starts_with(staticlib_prefix) && f.ends_with(staticlib_suffix.as_ref()) { self.crate_rejections.via_kind.push(CrateMismatch { |
