diff --git a/Cargo.lock b/Cargo.lock index 784177267..ebb750059 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -209,7 +209,6 @@ version = "0.0.0" dependencies = [ "libc", "nix", - "once_cell", ] [[package]] diff --git a/crates/common/Cargo.toml b/crates/common/Cargo.toml index 2b2f29df0..5a3159b44 100644 --- a/crates/common/Cargo.toml +++ b/crates/common/Cargo.toml @@ -9,7 +9,6 @@ license.workspace = true [dependencies] libc.workspace = true nix.workspace = true -once_cell.workspace = true [lints] workspace = true diff --git a/crates/common/src/lib.rs b/crates/common/src/lib.rs index fa51727fb..dffff0611 100644 --- a/crates/common/src/lib.rs +++ b/crates/common/src/lib.rs @@ -1,7 +1,7 @@ use libc::STDIN_FILENO; -use once_cell::sync::OnceCell; use std::env; use std::os::unix::ffi::OsStrExt; +use std::sync::OnceLock; // These are in the Unicode private-use range. We really shouldn't use this // range but have little choice in the matter given how our lexer/parser works. @@ -39,7 +39,7 @@ pub fn subslice_position(a: &[T], b: &[T]) -> Option { /// session. We err on the side of assuming it's not a console session. This approach isn't /// bullet-proof and that's OK. pub fn is_console_session() -> bool { - static IS_CONSOLE_SESSION: OnceCell = OnceCell::new(); + static IS_CONSOLE_SESSION: OnceLock = OnceLock::new(); // TODO(terminal-workaround) *IS_CONSOLE_SESSION.get_or_init(|| { nix::unistd::ttyname(unsafe { std::os::fd::BorrowedFd::borrow_raw(STDIN_FILENO) }) diff --git a/src/common.rs b/src/common.rs index eb033608a..33d650c04 100644 --- a/src/common.rs +++ b/src/common.rs @@ -20,7 +20,6 @@ use fish_fallback::fish_wcwidth; use fish_wchar::{decode_byte_from_char, encode_byte_to_char}; use libc::{SIG_IGN, SIGTTOU, STDIN_FILENO}; -use once_cell::sync::OnceCell; use std::cell::{Cell, RefCell}; use std::env; use std::ffi::{CStr, CString, OsString}; @@ -29,7 +28,7 @@ use std::ops::{Deref, DerefMut}; use std::os::unix::prelude::*; use std::sync::atomic::{AtomicI32, AtomicU32, Ordering}; -use std::sync::{Arc, MutexGuard}; +use std::sync::{Arc, MutexGuard, OnceLock}; use std::time; pub const BUILD_DIR: &str = env!("FISH_RESOLVED_BUILD_DIR"); @@ -1041,7 +1040,7 @@ pub fn get_obfuscation_read_char() -> char { pub static PROFILING_ACTIVE: RelaxedAtomicBool = RelaxedAtomicBool::new(false); /// Name of the current program. Should be set at startup. Used by the debug function. -pub static PROGRAM_NAME: OnceCell<&'static wstr> = OnceCell::new(); +pub static PROGRAM_NAME: OnceLock<&'static wstr> = OnceLock::new(); pub fn get_program_name() -> &'static wstr { PROGRAM_NAME.get().unwrap() diff --git a/src/env/config_paths.rs b/src/env/config_paths.rs index 02abb4800..377d67647 100644 --- a/src/env/config_paths.rs +++ b/src/env/config_paths.rs @@ -1,10 +1,10 @@ use crate::common::{BUILD_DIR, get_program_name}; use crate::{flog, flogf}; use fish_build_helper::workspace_root; -use once_cell::sync::OnceCell; use std::ffi::OsStr; use std::os::unix::ffi::OsStrExt; use std::path::{Path, PathBuf}; +use std::sync::OnceLock; /// A struct of configuration directories, determined in main() that fish will optionally pass to /// env_init. @@ -163,7 +163,7 @@ pub enum FishPath { LookUpInPath, } -static FISH_PATH: OnceCell = OnceCell::new(); +static FISH_PATH: OnceLock = OnceLock::new(); /// Get the absolute path to the fish executable itself pub fn get_fish_path() -> &'static FishPath { diff --git a/src/env/environment.rs b/src/env/environment.rs index 47c0c8a9b..d60817154 100644 --- a/src/env/environment.rs +++ b/src/env/environment.rs @@ -28,13 +28,12 @@ use crate::wutil::{fish_wcstol, wgetcwd}; use libc::{c_int, uid_t}; -use once_cell::sync::OnceCell; use std::collections::HashMap; use std::ffi::CStr; use std::mem::MaybeUninit; use std::os::unix::prelude::*; use std::path::PathBuf; -use std::sync::{Arc, LazyLock}; +use std::sync::{Arc, LazyLock, OnceLock}; /// Set when a universal variable has been modified but not yet been written to disk via sync(). static UVARS_LOCALLY_MODIFIED: RelaxedAtomicBool = RelaxedAtomicBool::new(false); @@ -624,7 +623,7 @@ fn setup_path(global_exported_mode: EnvSetMode) { /// The originally inherited variables and their values. /// This is a simple key->value map and not e.g. cut into paths. -pub static INHERITED_VARS: OnceCell> = OnceCell::new(); +pub static INHERITED_VARS: OnceLock> = OnceLock::new(); pub fn env_init(paths: Option<&ConfigPaths>, do_uvars: bool, default_paths: bool) { let vars = EnvStack::globals(); diff --git a/src/panic.rs b/src/panic.rs index f0b76927e..b7b7423f8 100644 --- a/src/panic.rs +++ b/src/panic.rs @@ -1,11 +1,13 @@ use std::{ panic::{UnwindSafe, set_hook, take_hook}, - sync::atomic::{AtomicBool, Ordering}, + sync::{ + OnceLock, + atomic::{AtomicBool, Ordering}, + }, time::Duration, }; use libc::STDIN_FILENO; -use once_cell::sync::OnceCell; use crate::{ common::{get_program_name, read_blocked}, @@ -13,7 +15,7 @@ threads::{asan_maybe_exit, is_main_thread}, }; -pub static AT_EXIT: OnceCell> = OnceCell::new(); +pub static AT_EXIT: OnceLock> = OnceLock::new(); pub fn panic_handler(main: impl FnOnce() -> i32 + UnwindSafe) -> ! { // The isatty() check will stop us from hanging in most fish tests, but not those diff --git a/src/reader/reader.rs b/src/reader/reader.rs index b34878a7b..72bca5bd4 100644 --- a/src/reader/reader.rs +++ b/src/reader/reader.rs @@ -42,7 +42,7 @@ #[cfg(target_has_atomic = "64")] use std::sync::atomic::AtomicU64; use std::sync::atomic::{AtomicI32, AtomicU8, AtomicU32, Ordering}; -use std::sync::{Arc, LazyLock, Mutex, MutexGuard}; +use std::sync::{Arc, LazyLock, Mutex, MutexGuard, OnceLock}; use std::time::{Duration, Instant}; use errno::{Errno, errno}; @@ -179,8 +179,7 @@ enum ExitState { /// The valid terminal modes on startup. /// Warning: this is read from the SIGTERM handler! Hence the raw global. -static TERMINAL_MODE_ON_STARTUP: once_cell::sync::OnceCell = - once_cell::sync::OnceCell::new(); +static TERMINAL_MODE_ON_STARTUP: OnceLock = OnceLock::new(); /// Mode we use to execute programs. static TTY_MODES_FOR_EXTERNAL_CMDS: LazyLock> = diff --git a/src/terminal.rs b/src/terminal.rs index f77cbdcec..27d8d64ee 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -9,7 +9,6 @@ use crate::text_face::{TextFace, TextStyling, UnderlineStyle}; use crate::threads::MainThread; use bitflags::bitflags; -use once_cell::sync::OnceCell; use std::cell::{RefCell, RefMut}; use std::env; use std::ffi::{CStr, CString}; @@ -17,9 +16,8 @@ use std::os::fd::RawFd; use std::os::unix::ffi::OsStrExt; use std::path::PathBuf; -use std::sync::Arc; -use std::sync::Mutex; use std::sync::atomic::{AtomicU8, Ordering}; +use std::sync::{Arc, Mutex, OnceLock}; bitflags! { #[derive(Copy, Clone, Default)] @@ -397,7 +395,7 @@ fn osc_133_prompt_start(out: &mut impl Output) -> bool { if !future_feature_flags::test(FeatureFlag::MarkPrompt) { return false; } - static TEST_BALLOON: OnceCell<()> = OnceCell::new(); + static TEST_BALLOON: OnceLock<()> = OnceLock::new(); if TEST_BALLOON.set(()).is_ok() { write_to_output!(out, "\x1b]133;A;click_events=1\x1b\\"); } else { diff --git a/src/tests/prelude.rs b/src/tests/prelude.rs index 6545ce323..5d2701477 100644 --- a/src/tests/prelude.rs +++ b/src/tests/prelude.rs @@ -9,16 +9,16 @@ use crate::topic_monitor::topic_monitor_init; use crate::wutil::wgetcwd; use crate::{env::EnvStack, proc::proc_init}; -use once_cell::sync::OnceCell; use std::cell::RefCell; use std::collections::HashMap; use std::env::set_current_dir; use std::path::PathBuf; +use std::sync::OnceLock; pub use serial_test::serial; pub fn test_init() -> impl ScopeGuarding { - static DONE: OnceCell<()> = OnceCell::new(); + static DONE: OnceLock<()> = OnceLock::new(); DONE.get_or_init(|| { // If we are building with `cargo build` and have build w/ `cmake`, this might not // yet exist. diff --git a/src/tty_handoff.rs b/src/tty_handoff.rs index 900abb44a..59d871287 100644 --- a/src/tty_handoff.rs +++ b/src/tty_handoff.rs @@ -20,19 +20,21 @@ use crate::wutil::{perror, wcstoi}; use fish_wchar::ToWString; use libc::{EINVAL, ENOTTY, EPERM, STDIN_FILENO, WNOHANG}; -use once_cell::sync::OnceCell; use std::mem::MaybeUninit; -use std::sync::atomic::{AtomicBool, AtomicPtr, Ordering}; +use std::sync::{ + OnceLock, + atomic::{AtomicBool, AtomicPtr, Ordering}, +}; /// Whether kitty keyboard protocol support is present in the TTY. -static KITTY_KEYBOARD_SUPPORTED: OnceCell = OnceCell::new(); +static KITTY_KEYBOARD_SUPPORTED: OnceLock = OnceLock::new(); /// Set that the TTY supports the kitty keyboard protocol. pub fn maybe_set_kitty_keyboard_capability() { KITTY_KEYBOARD_SUPPORTED.get_or_init(|| true); } -pub(crate) static SCROLL_CONTENT_UP_SUPPORTED: OnceCell = OnceCell::new(); +pub(crate) static SCROLL_CONTENT_UP_SUPPORTED: OnceLock = OnceLock::new(); pub(crate) const SCROLL_CONTENT_UP_TERMINFO_CODE: &str = "indn"; // Get the support capability for kitty keyboard protocol. @@ -47,10 +49,10 @@ pub fn maybe_set_scroll_content_up_capability() { }); } -pub static TERMINAL_OS_NAME: OnceCell> = OnceCell::new(); +pub static TERMINAL_OS_NAME: OnceLock> = OnceLock::new(); pub(crate) const XTGETTCAP_QUERY_OS_NAME: &str = "query-os-name"; -pub static XTVERSION: OnceCell = OnceCell::new(); +pub static XTVERSION: OnceLock = OnceLock::new(); pub fn xtversion() -> Option<&'static wstr> { XTVERSION.get().as_ref().map(|s| s.as_utfstr()) diff --git a/src/universal_notifier/mod.rs b/src/universal_notifier/mod.rs index 99ae3d28c..40262ae3d 100644 --- a/src/universal_notifier/mod.rs +++ b/src/universal_notifier/mod.rs @@ -1,5 +1,4 @@ -use once_cell::sync::OnceCell; -use std::os::fd::RawFd; +use std::{os::fd::RawFd, sync::OnceLock}; #[cfg(apple)] mod notifyd; @@ -69,7 +68,7 @@ pub fn create_notifier() -> Box { } // Default instance. Other instances are possible for testing. -static DEFAULT_NOTIFIER: OnceCell> = OnceCell::new(); +static DEFAULT_NOTIFIER: OnceLock> = OnceLock::new(); pub fn default_notifier() -> &'static dyn UniversalNotifier { DEFAULT_NOTIFIER.get_or_init(create_notifier).as_ref()