Skip to content

Commit d236fc6

Browse files
Try to fix unique file names on Windows
1 parent 05b3a4b commit d236fc6

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

crates/proc_macro_srv/src/dylib.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,9 @@ impl Expander {
188188
/// Copy the dylib to temp directory to prevent locking in Windows
189189
#[cfg(windows)]
190190
fn ensure_file_with_lock_free_access(path: &Path) -> io::Result<PathBuf> {
191-
use std::{ffi::OsString, time::SystemTime};
191+
use std::collections::hash_map::RandomState;
192+
use std::ffi::OsString;
193+
use std::hash::{BuildHasher, Hasher};
192194

193195
let mut to = std::env::temp_dir();
194196

@@ -199,10 +201,11 @@ fn ensure_file_with_lock_free_access(path: &Path) -> io::Result<PathBuf> {
199201
)
200202
})?;
201203

202-
// generate a time deps unique number
203-
let t = SystemTime::now().duration_since(std::time::UNIX_EPOCH).expect("Time went backwards");
204+
// Generate a unique number by abusing `HashMap`'s hasher.
205+
// Maybe this will also "inspire" a libs team member to finally put `rand` in libstd.
206+
let t = RandomState::new().build_hasher().finish();
204207

205-
let mut unique_name = OsString::from(t.as_millis().to_string());
208+
let mut unique_name = OsString::from(t.to_string());
206209
unique_name.push(file_name);
207210

208211
to.push(unique_name);

0 commit comments

Comments
 (0)