Skip to content

Commit 5f17b63

Browse files
anpMark-Simulacrum
authored andcommitted
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.
1 parent a08c562 commit 5f17b63

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

rustfmt.toml

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ ignore = [
2929
"src/librustc_data_structures/",
3030
"src/librustc_driver/",
3131
"src/librustc_errors/",
32-
"src/librustc_fs_util/",
3332
"src/librustc_feature/",
3433
"src/librustc_incremental/",
3534
"src/librustc_index/",

src/librustc_fs_util/lib.rs

+17-20
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use std::path::{Path, PathBuf};
21
use std::ffi::CString;
32
use std::fs;
43
use std::io;
4+
use std::path::{Path, PathBuf};
55

66
// Unfortunately, on windows, it looks like msvcrt.dll is silently translating
77
// verbatim paths under the hood to non-verbatim paths! This manifests itself as
@@ -21,8 +21,8 @@ use std::io;
2121
// https://github.com/rust-lang/rust/issues/25505#issuecomment-102876737
2222
#[cfg(windows)]
2323
pub fn fix_windows_verbatim_for_gcc(p: &Path) -> PathBuf {
24-
use std::path;
2524
use std::ffi::OsString;
25+
use std::path;
2626
let mut components = p.components();
2727
let prefix = match components.next() {
2828
Some(path::Component::Prefix(p)) => p,
@@ -68,12 +68,10 @@ pub fn link_or_copy<P: AsRef<Path>, Q: AsRef<Path>>(p: P, q: Q) -> io::Result<Li
6868

6969
match fs::hard_link(p, q) {
7070
Ok(()) => Ok(LinkOrCopy::Link),
71-
Err(_) => {
72-
match fs::copy(p, q) {
73-
Ok(_) => Ok(LinkOrCopy::Copy),
74-
Err(e) => Err(e),
75-
}
76-
}
71+
Err(_) => match fs::copy(p, q) {
72+
Ok(_) => Ok(LinkOrCopy::Copy),
73+
Err(e) => Err(e),
74+
},
7775
}
7876
}
7977

@@ -86,29 +84,28 @@ pub enum RenameOrCopyRemove {
8684
/// Rename `p` into `q`, preferring to use `rename` if possible.
8785
/// If `rename` fails (rename may fail for reasons such as crossing
8886
/// filesystem), fallback to copy & remove
89-
pub fn rename_or_copy_remove<P: AsRef<Path>, Q: AsRef<Path>>(p: P,
90-
q: Q)
91-
-> io::Result<RenameOrCopyRemove> {
87+
pub fn rename_or_copy_remove<P: AsRef<Path>, Q: AsRef<Path>>(
88+
p: P,
89+
q: Q,
90+
) -> io::Result<RenameOrCopyRemove> {
9291
let p = p.as_ref();
9392
let q = q.as_ref();
9493
match fs::rename(p, q) {
9594
Ok(()) => Ok(RenameOrCopyRemove::Rename),
96-
Err(_) => {
97-
match fs::copy(p, q) {
98-
Ok(_) => {
99-
fs::remove_file(p)?;
100-
Ok(RenameOrCopyRemove::CopyRemove)
101-
}
102-
Err(e) => Err(e),
95+
Err(_) => match fs::copy(p, q) {
96+
Ok(_) => {
97+
fs::remove_file(p)?;
98+
Ok(RenameOrCopyRemove::CopyRemove)
10399
}
104-
}
100+
Err(e) => Err(e),
101+
},
105102
}
106103
}
107104

108105
#[cfg(unix)]
109106
pub fn path_to_c_string(p: &Path) -> CString {
110-
use std::os::unix::ffi::OsStrExt;
111107
use std::ffi::OsStr;
108+
use std::os::unix::ffi::OsStrExt;
112109
let p: &OsStr = p.as_ref();
113110
CString::new(p.as_bytes()).unwrap()
114111
}

0 commit comments

Comments
 (0)