Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
chore: Replace lazy_static Mutex with const. (#2693)
Piotr Osiewiczabf3b4a54e66
diff --git a/Cargo.lock b/Cargo.lockindex ac089cee18e..60ed830683a 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -4004,7 +4004,6 @@ dependencies = ["gpui","hmac 0.12.1","jwt",- "lazy_static","live_kit_server","log","media",@@ -8398,7 +8397,6 @@ dependencies = ["indoc","itertools","language",- "lazy_static","log","nvim-rs","parking_lot 0.11.2",diff --git a/crates/collab/src/db.rs b/crates/collab/src/db.rsindex 208da22efe4..e16fa9edb1e 100644--- a/crates/collab/src/db.rs+++ b/crates/collab/src/db.rs@@ -3517,7 +3517,6 @@ pub use test::*;mod test {use super::*;use gpui::executor::Background;- use lazy_static::lazy_static;use parking_lot::Mutex;use sea_orm::ConnectionTrait;use sqlx::migrate::MigrateDatabase;@@ -3566,9 +3565,7 @@ mod test {}pub fn postgres(background: Arc<Background>) -> Self {- lazy_static! {- static ref LOCK: Mutex<()> = Mutex::new(());- }+ static LOCK: Mutex<()> = Mutex::new(());let _guard = LOCK.lock();let mut rng = StdRng::from_entropy();diff --git a/crates/collab/src/tests/randomized_integration_tests.rs b/crates/collab/src/tests/randomized_integration_tests.rsindex a95938f6b8d..f5dfe17d6f3 100644--- a/crates/collab/src/tests/randomized_integration_tests.rs+++ b/crates/collab/src/tests/randomized_integration_tests.rs@@ -37,9 +37,9 @@ use util::ResultExt;lazy_static::lazy_static! {static ref PLAN_LOAD_PATH: Option<PathBuf> = path_env_var("LOAD_PLAN");static ref PLAN_SAVE_PATH: Option<PathBuf> = path_env_var("SAVE_PLAN");- static ref LOADED_PLAN_JSON: Mutex<Option<Vec<u8>>> = Default::default();- static ref PLAN: Mutex<Option<Arc<Mutex<TestPlan>>>> = Default::default();}+static LOADED_PLAN_JSON: Mutex<Option<Vec<u8>>> = Mutex::new(None);+static PLAN: Mutex<Option<Arc<Mutex<TestPlan>>>> = Mutex::new(None);#[gpui::test(iterations = 100, on_failure = "on_failure")]async fn test_random_collaboration(diff --git a/crates/db/src/db.rs b/crates/db/src/db.rsindex 5b8aca07e03..798dfbc17f7 100644--- a/crates/db/src/db.rs+++ b/crates/db/src/db.rs@@ -43,10 +43,10 @@ const DB_FILE_NAME: &'static str = "db.sqlite";lazy_static::lazy_static! {// !!!!!!! CHANGE BACK TO DEFAULT FALSE BEFORE SHIPPINGstatic ref ZED_STATELESS: bool = std::env::var("ZED_STATELESS").map_or(false, |v| !v.is_empty());- static ref DB_FILE_OPERATIONS: Mutex<()> = Mutex::new(());pub static ref BACKUP_DB_PATH: RwLock<Option<PathBuf>> = RwLock::new(None);pub static ref ALL_FILE_DB_FAILED: AtomicBool = AtomicBool::new(false);}+static DB_FILE_OPERATIONS: Mutex<()> = Mutex::new(());/// Open or create a database at the given directory path./// This will retry a couple times if there are failures. If opening fails once, the db directorydiff --git a/crates/language/src/syntax_map.rs b/crates/language/src/syntax_map.rsindex 1570baf1854..b6431c22867 100644--- a/crates/language/src/syntax_map.rs+++ b/crates/language/src/syntax_map.rs@@ -4,7 +4,6 @@ mod syntax_map_tests;use crate::{Grammar, InjectionConfig, Language, LanguageRegistry};use collections::HashMap;use futures::FutureExt;-use lazy_static::lazy_static;use parking_lot::Mutex;use std::{borrow::Cow,@@ -25,9 +24,7 @@ thread_local! {static PARSER: RefCell<Parser> = RefCell::new(Parser::new());}-lazy_static! {- static ref QUERY_CURSORS: Mutex<Vec<QueryCursor>> = Default::default();-}+static QUERY_CURSORS: Mutex<Vec<QueryCursor>> = Mutex::new(vec![]);#[derive(Default)]pub struct SyntaxMap {diff --git a/crates/live_kit_client/Cargo.toml b/crates/live_kit_client/Cargo.tomlindex 36087a42a37..78f435906bc 100644--- a/crates/live_kit_client/Cargo.toml+++ b/crates/live_kit_client/Cargo.toml@@ -17,7 +17,6 @@ test-support = ["async-trait","collections/test-support","gpui/test-support",- "lazy_static","live_kit_server","nanoid",]@@ -38,7 +37,6 @@ parking_lot.workspace = truepostage.workspace = trueasync-trait = { workspace = true, optional = true }-lazy_static = { workspace = true, optional = true }nanoid = { version ="0.4", optional = true}[dev-dependencies]@@ -60,7 +58,6 @@ foreign-types = "0.3"futures.workspace = truehmac = "0.12"jwt = "0.16"-lazy_static.workspace = trueobjc = "0.2"parking_lot.workspace = trueserde.workspace = truediff --git a/crates/live_kit_client/src/test.rs b/crates/live_kit_client/src/test.rsindex 3fc046c5a29..ada864fc444 100644--- a/crates/live_kit_client/src/test.rs+++ b/crates/live_kit_client/src/test.rs@@ -1,18 +1,15 @@use anyhow::{anyhow, Result};use async_trait::async_trait;-use collections::HashMap;+use collections::{BTreeMap, HashMap};use futures::Stream;use gpui::executor::Background;-use lazy_static::lazy_static;use live_kit_server::token;use media::core_video::CVImageBuffer;use parking_lot::Mutex;use postage::watch;use std::{future::Future, mem, sync::Arc};-lazy_static! {- static ref SERVERS: Mutex<HashMap<String, Arc<TestServer>>> = Default::default();-}+static SERVERS: Mutex<BTreeMap<String, Arc<TestServer>>> = Mutex::new(BTreeMap::new());pub struct TestServer {pub url: String,diff --git a/crates/vim/Cargo.toml b/crates/vim/Cargo.tomlindex 57d38213798..47a85f4ed31 100644--- a/crates/vim/Cargo.toml+++ b/crates/vim/Cargo.toml@@ -36,7 +36,6 @@ workspace = { path = "../workspace" }[dev-dependencies]indoc.workspace = trueparking_lot.workspace = true-lazy_static.workspace = trueeditor = { path = "../editor", features = ["test-support"] }gpui = { path = "../gpui", features = ["test-support"] }diff --git a/crates/vim/src/test/neovim_connection.rs b/crates/vim/src/test/neovim_connection.rsindex c3916722dde..aa14e4a0651 100644--- a/crates/vim/src/test/neovim_connection.rs+++ b/crates/vim/src/test/neovim_connection.rs@@ -11,8 +11,6 @@ use gpui::keymap_matcher::Keystroke;use language::Point;-#[cfg(feature = "neovim")]-use lazy_static::lazy_static;#[cfg(feature = "neovim")]use nvim_rs::{create::tokio::new_child_cmd, error::LoopError, Handler, Neovim, UiAttachOptions, Value,@@ -32,9 +30,7 @@ use collections::VecDeque;// Neovim doesn't like to be started simultaneously from multiple threads. We use this lock// to ensure we are only constructing one neovim connection at a time.#[cfg(feature = "neovim")]-lazy_static! {- static ref NEOVIM_LOCK: ReentrantMutex<()> = ReentrantMutex::new(());-}+static NEOVIM_LOCK: ReentrantMutex<()> = ReentrantMutex::new(());#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]pub enum NeovimData {