]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_session/filesearch.rs
Auto merge of #67821 - matthiaskrgr:submodule_upd, r=Xanewok
[rust.git] / src / librustc_session / filesearch.rs
index a0bdc6a3254a151b07aaa27e48b7bd182497fd2c..05e6da43ea7a9cab916bca1a7ffcbb8104b669c9 100644 (file)
@@ -7,9 +7,9 @@
 use std::fs;
 use std::path::{Path, PathBuf};
 
-use crate::search_paths::{SearchPath, PathKind};
-use rustc_fs_util::fix_windows_verbatim_for_gcc;
+use crate::search_paths::{PathKind, SearchPath};
 use log::debug;
+use rustc_fs_util::fix_windows_verbatim_for_gcc;
 
 #[derive(Copy, Clone)]
 pub enum FileMatch {
@@ -31,7 +31,8 @@ pub struct FileSearch<'a> {
 impl<'a> FileSearch<'a> {
     pub fn search_paths(&self) -> impl Iterator<Item = &'a SearchPath> {
         let kind = self.kind;
-        self.search_paths.iter()
+        self.search_paths
+            .iter()
             .filter(move |sp| sp.kind.matches(kind))
             .chain(std::iter::once(self.tlib_path))
     }
@@ -41,7 +42,8 @@ pub fn get_lib_path(&self) -> PathBuf {
     }
 
     pub fn search<F>(&self, mut pick: F)
-        where F: FnMut(&Path, PathKind) -> FileMatch
+    where
+        F: FnMut(&Path, PathKind) -> FileMatch,
     {
         for search_path in self.search_paths() {
             debug!("searching {}", search_path.dir.display());
@@ -69,27 +71,20 @@ fn is_rlib(p: &Path) -> bool {
         }
     }
 
-    pub fn new(sysroot: &'a Path,
-               triple: &'a str,
-               search_paths: &'a Vec<SearchPath>,
-               tlib_path: &'a SearchPath,
-               kind: PathKind)
-               -> FileSearch<'a> {
+    pub fn new(
+        sysroot: &'a Path,
+        triple: &'a str,
+        search_paths: &'a Vec<SearchPath>,
+        tlib_path: &'a SearchPath,
+        kind: PathKind,
+    ) -> FileSearch<'a> {
         debug!("using sysroot = {}, triple = {}", sysroot.display(), triple);
-        FileSearch {
-            sysroot,
-            triple,
-            search_paths,
-            tlib_path,
-            kind,
-        }
+        FileSearch { sysroot, triple, search_paths, tlib_path, kind }
     }
 
     // Returns just the directories within the search paths.
     pub fn search_path_dirs(&self) -> Vec<PathBuf> {
-        self.search_paths()
-            .map(|sp| sp.dir.to_path_buf())
-            .collect()
+        self.search_paths().map(|sp| sp.dir.to_path_buf()).collect()
     }
 
     // Returns a list of directories where target-specific tool binaries are located.
@@ -131,13 +126,15 @@ fn canonicalize(path: Option<PathBuf>) -> Option<PathBuf> {
     }
 
     match env::current_exe() {
-        Ok(exe) => {
-            match canonicalize(Some(exe)) {
-                Some(mut p) => { p.pop(); p.pop(); p },
-                None => panic!("can't determine value for sysroot")
+        Ok(exe) => match canonicalize(Some(exe)) {
+            Some(mut p) => {
+                p.pop();
+                p.pop();
+                p
             }
-        }
-        Err(ref e) => panic!(format!("failed to get current_exe: {}", e))
+            None => panic!("can't determine value for sysroot"),
+        },
+        Err(ref e) => panic!(format!("failed to get current_exe: {}", e)),
     }
 }
 
@@ -161,10 +158,12 @@ fn find_libdir(sysroot: &Path) -> Cow<'static, str> {
 
     match option_env!("CFG_LIBDIR_RELATIVE") {
         Some(libdir) if libdir != "lib" => libdir.into(),
-        _ => if sysroot.join(PRIMARY_LIB_DIR).join(RUST_LIB_DIR).exists() {
-            PRIMARY_LIB_DIR.into()
-        } else {
-            SECONDARY_LIB_DIR.into()
+        _ => {
+            if sysroot.join(PRIMARY_LIB_DIR).join(RUST_LIB_DIR).exists() {
+                PRIMARY_LIB_DIR.into()
+            } else {
+                SECONDARY_LIB_DIR.into()
+            }
         }
     }
 }