From 1a9f0a647a70623392faf0ad8d7b1732481e1fb1 Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Wed, 25 Dec 2024 01:33:26 +0100 Subject: [PATCH] chore: Remove explicit usages of once_cell in favor of std (#22407) Closes #ISSUE Release Notes: - N/A --- Cargo.lock | 3 --- Cargo.toml | 1 - crates/cli/Cargo.toml | 1 - crates/cli/src/main.rs | 6 +++--- crates/client/Cargo.toml | 1 - crates/client/src/telemetry.rs | 10 +++++++--- crates/release_channel/Cargo.toml | 1 - crates/release_channel/src/lib.rs | 19 +++++++++---------- 8 files changed, 19 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 714116d716510c..9431840f36f493 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2484,7 +2484,6 @@ dependencies = [ "exec", "fork", "ipc-channel", - "once_cell", "parking_lot", "paths", "plist", @@ -2511,7 +2510,6 @@ dependencies = [ "gpui", "http_client", "log", - "once_cell", "parking_lot", "paths", "postage", @@ -10266,7 +10264,6 @@ name = "release_channel" version = "0.1.0" dependencies = [ "gpui", - "once_cell", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index a888d868cf90e0..779ebb1b35d448 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -408,7 +408,6 @@ nanoid = "0.4" nbformat = { version = "0.9.0" } nix = "0.29" num-format = "0.4.4" -once_cell = "1.19.0" ordered-float = "2.1.1" palette = { version = "0.7.5", default-features = false, features = ["std"] } parking_lot = "0.12.1" diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index fedd6738ed1839..170647873ad0a1 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -25,7 +25,6 @@ anyhow.workspace = true clap.workspace = true collections.workspace = true ipc-channel = "0.19" -once_cell.workspace = true parking_lot.workspace = true paths.workspace = true release_channel.workspace = true diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 1f0aa459e05f87..3dbfa0e737ae86 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -277,6 +277,7 @@ mod linux { os::unix::net::{SocketAddr, UnixDatagram}, path::{Path, PathBuf}, process::{self, ExitStatus}, + sync::LazyLock, thread, time::Duration, }; @@ -284,12 +285,11 @@ mod linux { use anyhow::anyhow; use cli::FORCE_CLI_MODE_ENV_VAR_NAME; use fork::Fork; - use once_cell::sync::Lazy; use crate::{Detect, InstalledApp}; - static RELEASE_CHANNEL: Lazy = - Lazy::new(|| include_str!("../../zed/RELEASE_CHANNEL").trim().to_string()); + static RELEASE_CHANNEL: LazyLock = + LazyLock::new(|| include_str!("../../zed/RELEASE_CHANNEL").trim().to_string()); struct App(PathBuf); diff --git a/crates/client/Cargo.toml b/crates/client/Cargo.toml index c68caa0108b129..debf2ea8247641 100644 --- a/crates/client/Cargo.toml +++ b/crates/client/Cargo.toml @@ -27,7 +27,6 @@ futures.workspace = true gpui.workspace = true http_client.workspace = true log.workspace = true -once_cell.workspace = true paths.workspace = true parking_lot.workspace = true postage.workspace = true diff --git a/crates/client/src/telemetry.rs b/crates/client/src/telemetry.rs index 54f3cd642b9f33..96e539e167d65c 100644 --- a/crates/client/src/telemetry.rs +++ b/crates/client/src/telemetry.rs @@ -8,7 +8,6 @@ use futures::channel::mpsc; use futures::{Future, StreamExt}; use gpui::{AppContext, BackgroundExecutor, Task}; use http_client::{self, AsyncBody, HttpClient, HttpClientWithUrl, Method, Request}; -use once_cell::sync::Lazy; use parking_lot::Mutex; use release_channel::ReleaseChannel; use settings::{Settings, SettingsStore}; @@ -16,7 +15,12 @@ use sha2::{Digest, Sha256}; use std::fs::File; use std::io::Write; use std::time::Instant; -use std::{env, mem, path::PathBuf, sync::Arc, time::Duration}; +use std::{ + env, mem, + path::PathBuf, + sync::{Arc, LazyLock}, + time::Duration, +}; use telemetry_events::{ AppEvent, AssistantEvent, CallEvent, EditEvent, Event, EventRequestBody, EventWrapper, InlineCompletionEvent, @@ -84,7 +88,7 @@ const FLUSH_INTERVAL: Duration = Duration::from_secs(1); #[cfg(not(debug_assertions))] const FLUSH_INTERVAL: Duration = Duration::from_secs(60 * 5); -static ZED_CLIENT_CHECKSUM_SEED: Lazy>> = Lazy::new(|| { +static ZED_CLIENT_CHECKSUM_SEED: LazyLock>> = LazyLock::new(|| { option_env!("ZED_CLIENT_CHECKSUM_SEED") .map(|s| s.as_bytes().into()) .or_else(|| { diff --git a/crates/release_channel/Cargo.toml b/crates/release_channel/Cargo.toml index cf664ceff1c154..7c12194674866b 100644 --- a/crates/release_channel/Cargo.toml +++ b/crates/release_channel/Cargo.toml @@ -10,4 +10,3 @@ workspace = true [dependencies] gpui.workspace = true -once_cell.workspace = true diff --git a/crates/release_channel/src/lib.rs b/crates/release_channel/src/lib.rs index 602c4f4b5fe265..a41c4de22607e7 100644 --- a/crates/release_channel/src/lib.rs +++ b/crates/release_channel/src/lib.rs @@ -2,24 +2,23 @@ #![deny(missing_docs)] -use std::{env, str::FromStr}; +use std::{env, str::FromStr, sync::LazyLock}; use gpui::{AppContext, Global, SemanticVersion}; -use once_cell::sync::Lazy; /// stable | dev | nightly | preview -pub static RELEASE_CHANNEL_NAME: Lazy = if cfg!(debug_assertions) { - Lazy::new(|| { +pub static RELEASE_CHANNEL_NAME: LazyLock = LazyLock::new(|| { + if cfg!(debug_assertions) { env::var("ZED_RELEASE_CHANNEL") .unwrap_or_else(|_| include_str!("../../zed/RELEASE_CHANNEL").trim().to_string()) - }) -} else { - Lazy::new(|| include_str!("../../zed/RELEASE_CHANNEL").trim().to_string()) -}; + } else { + include_str!("../../zed/RELEASE_CHANNEL").trim().to_string() + } +}); #[doc(hidden)] -pub static RELEASE_CHANNEL: Lazy = - Lazy::new(|| match ReleaseChannel::from_str(&RELEASE_CHANNEL_NAME) { +pub static RELEASE_CHANNEL: LazyLock = + LazyLock::new(|| match ReleaseChannel::from_str(&RELEASE_CHANNEL_NAME) { Ok(channel) => channel, _ => panic!("invalid release channel {}", *RELEASE_CHANNEL_NAME), });