chore: Replace lazy_static Mutex with const. (#2693)

Mutex::new() is const-stable as of Rust 1.63.

Release Notes:
- N/A
This commit is contained in:
Piotr Osiewicz 2023-07-07 15:07:12 +02:00 committed by GitHub
parent 79ece8a86e
commit abf3b4a54e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 8 additions and 27 deletions

2
Cargo.lock generated
View File

@ -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",

View File

@ -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();

View File

@ -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(

View File

@ -43,10 +43,10 @@ const DB_FILE_NAME: &'static str = "db.sqlite";
lazy_static::lazy_static! {
// !!!!!!! CHANGE BACK TO DEFAULT FALSE BEFORE SHIPPING
static 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 directory

View File

@ -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 {

View File

@ -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 = true
postage.workspace = true
async-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 = true
hmac = "0.12"
jwt = "0.16"
lazy_static.workspace = true
objc = "0.2"
parking_lot.workspace = true
serde.workspace = true

View File

@ -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,

View File

@ -36,7 +36,6 @@ workspace = { path = "../workspace" }
[dev-dependencies]
indoc.workspace = true
parking_lot.workspace = true
lazy_static.workspace = true
editor = { path = "../editor", features = ["test-support"] }
gpui = { path = "../gpui", features = ["test-support"] }

View File

@ -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 {