Skip to content

Commit d7769b9

Browse files
committed
Auto merge of #80754 - sunfishcode:path-cleanup/rustc-fs-util, r=davidtwco
Optimize away a `fs::metadata` call. This also eliminates a use of a `Path` convenience function, in support of #80741, refactoring `std::path` to focus on pure data structures and algorithms.
2 parents c2de47a + 68338bc commit d7769b9

File tree

1 file changed

+4
-2
lines changed
  • compiler/rustc_fs_util/src

1 file changed

+4
-2
lines changed

compiler/rustc_fs_util/src/lib.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@ pub enum LinkOrCopy {
6262
pub fn link_or_copy<P: AsRef<Path>, Q: AsRef<Path>>(p: P, q: Q) -> io::Result<LinkOrCopy> {
6363
let p = p.as_ref();
6464
let q = q.as_ref();
65-
if q.exists() {
66-
fs::remove_file(&q)?;
65+
match fs::remove_file(&q) {
66+
Ok(()) => (),
67+
Err(err) if err.kind() == io::ErrorKind::NotFound => (),
68+
Err(err) => return Err(err),
6769
}
6870

6971
match fs::hard_link(p, q) {

0 commit comments

Comments
 (0)