Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 4c52ed4

Browse files
authored
Merge pull request rust-lang#18697 from Veykril/push-qtmmtvpyrntr
internal: Simplify ratoml testdir usage
2 parents 5c6bae0 + 1cace0a commit 4c52ed4

File tree

1 file changed

+9
-30
lines changed
  • src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests

1 file changed

+9
-30
lines changed

src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/support.rs

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{
22
cell::{Cell, RefCell},
33
env, fs,
4-
sync::{Once, OnceLock},
4+
sync::Once,
55
time::Duration,
66
};
77

@@ -141,34 +141,15 @@ impl Project<'_> {
141141
/// file in the config dir after server is run, something where our naive approach comes short.
142142
/// Using a `prelock` allows us to force a lock when we know we need it.
143143
pub(crate) fn server_with_lock(self, config_lock: bool) -> Server {
144-
static CONFIG_DIR_LOCK: OnceLock<(Utf8PathBuf, Mutex<()>)> = OnceLock::new();
144+
static CONFIG_DIR_LOCK: Mutex<()> = Mutex::new(());
145145

146146
let config_dir_guard = if config_lock {
147147
Some({
148-
let (path, mutex) = CONFIG_DIR_LOCK.get_or_init(|| {
149-
let value = TestDir::new().keep().path().to_owned();
150-
env::set_var("__TEST_RA_USER_CONFIG_DIR", &value);
151-
(value, Mutex::new(()))
152-
});
153-
#[allow(dyn_drop)]
154-
(mutex.lock(), {
155-
Box::new({
156-
struct Dropper(Utf8PathBuf);
157-
impl Drop for Dropper {
158-
fn drop(&mut self) {
159-
for entry in fs::read_dir(&self.0).unwrap() {
160-
let path = entry.unwrap().path();
161-
if path.is_file() {
162-
fs::remove_file(path).unwrap();
163-
} else if path.is_dir() {
164-
fs::remove_dir_all(path).unwrap();
165-
}
166-
}
167-
}
168-
}
169-
Dropper(path.clone())
170-
}) as Box<dyn Drop>
171-
})
148+
let guard = CONFIG_DIR_LOCK.lock();
149+
let test_dir = TestDir::new();
150+
let value = test_dir.path().to_owned();
151+
env::set_var("__TEST_RA_USER_CONFIG_DIR", &value);
152+
(guard, test_dir)
172153
})
173154
} else {
174155
None
@@ -311,14 +292,12 @@ pub(crate) struct Server {
311292
client: Connection,
312293
/// XXX: remove the tempdir last
313294
dir: TestDir,
314-
#[allow(dyn_drop)]
315-
_config_dir_guard: Option<(MutexGuard<'static, ()>, Box<dyn Drop>)>,
295+
_config_dir_guard: Option<(MutexGuard<'static, ()>, TestDir)>,
316296
}
317297

318298
impl Server {
319-
#[allow(dyn_drop)]
320299
fn new(
321-
config_dir_guard: Option<(MutexGuard<'static, ()>, Box<dyn Drop>)>,
300+
config_dir_guard: Option<(MutexGuard<'static, ()>, TestDir)>,
322301
dir: TestDir,
323302
config: Config,
324303
) -> Server {

0 commit comments

Comments
 (0)