about summary refs log tree commit diff
path: root/src/tools/rust-analyzer
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2024-12-16 09:16:18 +0000
committerGitHub <noreply@github.com>2024-12-16 09:16:18 +0000
commit4c52ed4286e659698ad06ede75d166d92ecce2b9 (patch)
tree95b6a24744832bf7c8fae1861a7d8a032b6af6b5 /src/tools/rust-analyzer
parent5c6bae0fc0930d57dba2e279c0b67a4397b3999c (diff)
parent1cace0aa4135acad746516992bd8e6a89e4fd861 (diff)
downloadrust-4c52ed4286e659698ad06ede75d166d92ecce2b9.tar.gz
rust-4c52ed4286e659698ad06ede75d166d92ecce2b9.zip
Merge pull request #18697 from Veykril/push-qtmmtvpyrntr
internal: Simplify ratoml testdir usage
Diffstat (limited to 'src/tools/rust-analyzer')
-rw-r--r--src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/support.rs39
1 files changed, 9 insertions, 30 deletions
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/support.rs b/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/support.rs
index 5a88a5515c7..1f52f366c54 100644
--- a/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/support.rs
+++ b/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/support.rs
@@ -1,7 +1,7 @@
 use std::{
     cell::{Cell, RefCell},
     env, fs,
-    sync::{Once, OnceLock},
+    sync::Once,
     time::Duration,
 };
 
@@ -141,34 +141,15 @@ impl Project<'_> {
     /// file in the config dir after server is run, something where our naive approach comes short.
     /// Using a `prelock` allows us to force a lock when we know we need it.
     pub(crate) fn server_with_lock(self, config_lock: bool) -> Server {
-        static CONFIG_DIR_LOCK: OnceLock<(Utf8PathBuf, Mutex<()>)> = OnceLock::new();
+        static CONFIG_DIR_LOCK: Mutex<()> = Mutex::new(());
 
         let config_dir_guard = if config_lock {
             Some({
-                let (path, mutex) = CONFIG_DIR_LOCK.get_or_init(|| {
-                    let value = TestDir::new().keep().path().to_owned();
-                    env::set_var("__TEST_RA_USER_CONFIG_DIR", &value);
-                    (value, Mutex::new(()))
-                });
-                #[allow(dyn_drop)]
-                (mutex.lock(), {
-                    Box::new({
-                        struct Dropper(Utf8PathBuf);
-                        impl Drop for Dropper {
-                            fn drop(&mut self) {
-                                for entry in fs::read_dir(&self.0).unwrap() {
-                                    let path = entry.unwrap().path();
-                                    if path.is_file() {
-                                        fs::remove_file(path).unwrap();
-                                    } else if path.is_dir() {
-                                        fs::remove_dir_all(path).unwrap();
-                                    }
-                                }
-                            }
-                        }
-                        Dropper(path.clone())
-                    }) as Box<dyn Drop>
-                })
+                let guard = CONFIG_DIR_LOCK.lock();
+                let test_dir = TestDir::new();
+                let value = test_dir.path().to_owned();
+                env::set_var("__TEST_RA_USER_CONFIG_DIR", &value);
+                (guard, test_dir)
             })
         } else {
             None
@@ -311,14 +292,12 @@ pub(crate) struct Server {
     client: Connection,
     /// XXX: remove the tempdir last
     dir: TestDir,
-    #[allow(dyn_drop)]
-    _config_dir_guard: Option<(MutexGuard<'static, ()>, Box<dyn Drop>)>,
+    _config_dir_guard: Option<(MutexGuard<'static, ()>, TestDir)>,
 }
 
 impl Server {
-    #[allow(dyn_drop)]
     fn new(
-        config_dir_guard: Option<(MutexGuard<'static, ()>, Box<dyn Drop>)>,
+        config_dir_guard: Option<(MutexGuard<'static, ()>, TestDir)>,
         dir: TestDir,
         config: Config,
     ) -> Server {