diff --git a/compiler/rustc_metadata/src/locator.rs b/compiler/rustc_metadata/src/locator.rs index 8db65a10c13..f65cd73007b 100644 --- a/compiler/rustc_metadata/src/locator.rs +++ b/compiler/rustc_metadata/src/locator.rs @@ -394,44 +394,55 @@ impl<'a> CrateLocator<'a> { // of the crate id (path/name/id). // // The goal of this step is to look at as little metadata as possible. - self.filesearch.search(|spf, kind| { - let file = match &spf.file_name_str { - None => return, - Some(file) => file, - }; - let (hash, found_kind) = if file.starts_with(&rlib_prefix) && file.ends_with(".rlib") { - (&file[(rlib_prefix.len())..(file.len() - ".rlib".len())], CrateFlavor::Rlib) - } else if file.starts_with(&rlib_prefix) && file.ends_with(".rmeta") { - (&file[(rlib_prefix.len())..(file.len() - ".rmeta".len())], CrateFlavor::Rmeta) - } else if file.starts_with(&dylib_prefix) && file.ends_with(&self.target.dll_suffix) { - ( - &file[(dylib_prefix.len())..(file.len() - self.target.dll_suffix.len())], - CrateFlavor::Dylib, - ) - } else { - if file.starts_with(&staticlib_prefix) - && file.ends_with(&self.target.staticlib_suffix) + for search_path in self.filesearch.search_paths() { + debug!("searching {}", search_path.dir.display()); + for spf in search_path.files.iter() { + debug!("testing {}", spf.path.display()); + + let file = match &spf.file_name_str { + None => continue, + Some(file) => file, + }; + let (hash, found_kind) = if file.starts_with(&rlib_prefix) + && file.ends_with(".rlib") { - staticlibs - .push(CrateMismatch { path: spf.path.clone(), got: "static".to_string() }); - } - return; - }; + (&file[(rlib_prefix.len())..(file.len() - ".rlib".len())], CrateFlavor::Rlib) + } else if file.starts_with(&rlib_prefix) && file.ends_with(".rmeta") { + (&file[(rlib_prefix.len())..(file.len() - ".rmeta".len())], CrateFlavor::Rmeta) + } else if file.starts_with(&dylib_prefix) && file.ends_with(&self.target.dll_suffix) + { + ( + &file[(dylib_prefix.len())..(file.len() - self.target.dll_suffix.len())], + CrateFlavor::Dylib, + ) + } else { + if file.starts_with(&staticlib_prefix) + && file.ends_with(&self.target.staticlib_suffix) + { + staticlibs.push(CrateMismatch { + path: spf.path.clone(), + got: "static".to_string(), + }); + } + continue; + }; - info!("lib candidate: {}", spf.path.display()); + info!("lib candidate: {}", spf.path.display()); + + let (rlibs, rmetas, dylibs) = candidates.entry(hash.to_string()).or_default(); + let path = fs::canonicalize(&spf.path).unwrap_or_else(|_| spf.path.clone()); + if seen_paths.contains(&path) { + continue; + }; + seen_paths.insert(path.clone()); + match found_kind { + CrateFlavor::Rlib => rlibs.insert(path, search_path.kind), + CrateFlavor::Rmeta => rmetas.insert(path, search_path.kind), + CrateFlavor::Dylib => dylibs.insert(path, search_path.kind), + }; + } + } - let (rlibs, rmetas, dylibs) = candidates.entry(hash.to_string()).or_default(); - let path = fs::canonicalize(&spf.path).unwrap_or_else(|_| spf.path.clone()); - if seen_paths.contains(&path) { - return; - }; - seen_paths.insert(path.clone()); - match found_kind { - CrateFlavor::Rlib => rlibs.insert(path, kind), - CrateFlavor::Rmeta => rmetas.insert(path, kind), - CrateFlavor::Dylib => dylibs.insert(path, kind), - }; - }); self.crate_rejections.via_kind.extend(staticlibs); // We have now collected all known libraries into a set of candidates diff --git a/compiler/rustc_session/src/filesearch.rs b/compiler/rustc_session/src/filesearch.rs index e6ec16b393b..9200be363ad 100644 --- a/compiler/rustc_session/src/filesearch.rs +++ b/compiler/rustc_session/src/filesearch.rs @@ -5,7 +5,7 @@ use std::fs; use std::iter::FromIterator; use std::path::{Path, PathBuf}; -use crate::search_paths::{PathKind, SearchPath, SearchPathFile}; +use crate::search_paths::{PathKind, SearchPath}; use rustc_fs_util::fix_windows_verbatim_for_gcc; use tracing::debug; @@ -41,19 +41,6 @@ impl<'a> FileSearch<'a> { self.get_lib_path().join("self-contained") } - pub fn search(&self, mut pick: F) - where - F: FnMut(&SearchPathFile, PathKind), - { - for search_path in self.search_paths() { - debug!("searching {}", search_path.dir.display()); - for spf in search_path.files.iter() { - debug!("testing {}", spf.path.display()); - pick(spf, search_path.kind); - } - } - } - pub fn new( sysroot: &'a Path, triple: &'a str,