From 5f17b63dacabc45620d9021a033e064ccffa30c7 Mon Sep 17 00:00:00 2001 From: Adam Perry Date: Mon, 4 Nov 2019 08:28:40 -0800 Subject: [PATCH] Format src/librustc_fs_util. In total it's about 100 lines of code and has received less than 5 commits in 2019 -- a good starting point. --- rustfmt.toml | 1 - src/librustc_fs_util/lib.rs | 37 +++++++++++++++++-------------------- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/rustfmt.toml b/rustfmt.toml index a25324273f2..bb656891446 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -29,7 +29,6 @@ ignore = [ "src/librustc_data_structures/", "src/librustc_driver/", "src/librustc_errors/", - "src/librustc_fs_util/", "src/librustc_feature/", "src/librustc_incremental/", "src/librustc_index/", diff --git a/src/librustc_fs_util/lib.rs b/src/librustc_fs_util/lib.rs index eaf08d76b99..289b9f30c3b 100644 --- a/src/librustc_fs_util/lib.rs +++ b/src/librustc_fs_util/lib.rs @@ -1,7 +1,7 @@ -use std::path::{Path, PathBuf}; use std::ffi::CString; use std::fs; use std::io; +use std::path::{Path, PathBuf}; // Unfortunately, on windows, it looks like msvcrt.dll is silently translating // verbatim paths under the hood to non-verbatim paths! This manifests itself as @@ -21,8 +21,8 @@ use std::io; // https://github.com/rust-lang/rust/issues/25505#issuecomment-102876737 #[cfg(windows)] pub fn fix_windows_verbatim_for_gcc(p: &Path) -> PathBuf { - use std::path; use std::ffi::OsString; + use std::path; let mut components = p.components(); let prefix = match components.next() { Some(path::Component::Prefix(p)) => p, @@ -68,12 +68,10 @@ pub fn link_or_copy, Q: AsRef>(p: P, q: Q) -> io::Result
  • Ok(LinkOrCopy::Link), - Err(_) => { - match fs::copy(p, q) { - Ok(_) => Ok(LinkOrCopy::Copy), - Err(e) => Err(e), - } - } + Err(_) => match fs::copy(p, q) { + Ok(_) => Ok(LinkOrCopy::Copy), + Err(e) => Err(e), + }, } } @@ -86,29 +84,28 @@ pub enum RenameOrCopyRemove { /// Rename `p` into `q`, preferring to use `rename` if possible. /// If `rename` fails (rename may fail for reasons such as crossing /// filesystem), fallback to copy & remove -pub fn rename_or_copy_remove, Q: AsRef>(p: P, - q: Q) - -> io::Result { +pub fn rename_or_copy_remove, Q: AsRef>( + p: P, + q: Q, +) -> io::Result { let p = p.as_ref(); let q = q.as_ref(); match fs::rename(p, q) { Ok(()) => Ok(RenameOrCopyRemove::Rename), - Err(_) => { - match fs::copy(p, q) { - Ok(_) => { - fs::remove_file(p)?; - Ok(RenameOrCopyRemove::CopyRemove) - } - Err(e) => Err(e), + Err(_) => match fs::copy(p, q) { + Ok(_) => { + fs::remove_file(p)?; + Ok(RenameOrCopyRemove::CopyRemove) } - } + Err(e) => Err(e), + }, } } #[cfg(unix)] pub fn path_to_c_string(p: &Path) -> CString { - use std::os::unix::ffi::OsStrExt; use std::ffi::OsStr; + use std::os::unix::ffi::OsStrExt; let p: &OsStr = p.as_ref(); CString::new(p.as_bytes()).unwrap() }