From 80e1942980a5ec8fca89e6b57e8f50da781fe720 Mon Sep 17 00:00:00 2001 From: Daniel Rainer Date: Tue, 6 Jan 2026 19:48:04 +0100 Subject: [PATCH] sync: `once_cell::sync::Lazy` -> `std::sync::LazyLock` Rust 1.80 stabilized `std::sync::LazyLock`, which replaces `once_cell::sync::Lazy`. There is one exception in `src/env_dispatch.rs`, which still uses the `once_cell` variant, since the code there relies on `Lazy::get`, which also exists for `LazyLock`, but will only be stabilized in Rust 1.94, so we can't use it yet. Part of #12289 --- Cargo.lock | 2 -- crates/fallback/Cargo.toml | 1 - crates/fallback/src/lib.rs | 8 +++++--- crates/gettext/Cargo.toml | 1 - crates/gettext/src/lib.rs | 5 ++--- src/abbrs.rs | 5 ++--- src/builtins/random.rs | 7 +++---- src/builtins/test.rs | 4 ++-- src/builtins/ulimit.rs | 5 ++--- src/complete.rs | 9 ++++----- src/env/environment.rs | 6 +++--- src/env/environment_impl.rs | 4 ++-- src/env_dispatch.rs | 1 + src/function.rs | 5 ++--- src/input.rs | 7 +++---- src/io.rs | 5 ++--- src/kill.rs | 5 ++--- src/localization/gettext.rs | 11 +++++------ src/localization/settings.rs | 7 +++---- src/path.rs | 14 +++++++------- src/proc.rs | 7 +++---- src/reader/reader.rs | 11 +++++------ src/signal.rs | 8 +++++--- src/wildcard.rs | 6 +++--- 24 files changed, 66 insertions(+), 78 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e4021c8c2..784177267 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -221,7 +221,6 @@ dependencies = [ "fish-wchar", "fish-widecharwidth", "libc", - "once_cell", "rsconf", "widestring", ] @@ -231,7 +230,6 @@ name = "fish-gettext" version = "0.0.0" dependencies = [ "fish-gettext-maps", - "once_cell", "phf 0.13.1", ] diff --git a/crates/fallback/Cargo.toml b/crates/fallback/Cargo.toml index dce8fbe1a..b0895f55c 100644 --- a/crates/fallback/Cargo.toml +++ b/crates/fallback/Cargo.toml @@ -11,7 +11,6 @@ fish-common.workspace = true fish-wchar.workspace = true fish-widecharwidth.workspace = true libc.workspace = true -once_cell.workspace = true widestring.workspace = true [build-dependencies] diff --git a/crates/fallback/src/lib.rs b/crates/fallback/src/lib.rs index eefc40657..3e2075df2 100644 --- a/crates/fallback/src/lib.rs +++ b/crates/fallback/src/lib.rs @@ -5,9 +5,11 @@ use fish_wchar::prelude::*; use fish_widecharwidth::{WcLookupTable, WcWidth}; -use once_cell::sync::Lazy; use std::cmp; -use std::sync::atomic::{AtomicIsize, Ordering}; +use std::sync::{ + LazyLock, + atomic::{AtomicIsize, Ordering}, +}; /// Width of ambiguous East Asian characters and, as of TR11, all private-use characters. /// 1 is the typical default, but we accept any non-negative override via `$fish_ambiguous_width`. @@ -25,7 +27,7 @@ // For some reason, this is declared here and exposed here, but is set in `env_dispatch`. pub static FISH_EMOJI_WIDTH: AtomicIsize = AtomicIsize::new(1); -static WC_LOOKUP_TABLE: Lazy = Lazy::new(WcLookupTable::new); +static WC_LOOKUP_TABLE: LazyLock = LazyLock::new(WcLookupTable::new); /// A safe wrapper around the system `wcwidth()` function #[cfg(not(cygwin))] diff --git a/crates/gettext/Cargo.toml b/crates/gettext/Cargo.toml index 155fbba32..396dd49bc 100644 --- a/crates/gettext/Cargo.toml +++ b/crates/gettext/Cargo.toml @@ -8,7 +8,6 @@ license.workspace = true [dependencies] fish-gettext-maps.workspace = true -once_cell.workspace = true phf.workspace = true [lints] diff --git a/crates/gettext/src/lib.rs b/crates/gettext/src/lib.rs index 05fb279e7..cdba800bb 100644 --- a/crates/gettext/src/lib.rs +++ b/crates/gettext/src/lib.rs @@ -1,5 +1,4 @@ use fish_gettext_maps::CATALOGS; -use once_cell::sync::Lazy; use std::{ collections::HashMap, sync::{LazyLock, Mutex}, @@ -7,8 +6,8 @@ type Catalog = &'static phf::Map<&'static str, &'static str>; -static LANGUAGE_PRECEDENCE: Lazy>> = - Lazy::new(|| Mutex::new(vec![])); +static LANGUAGE_PRECEDENCE: LazyLock>> = + LazyLock::new(|| Mutex::new(vec![])); pub fn gettext(message_str: &'static str) -> Option<&'static str> { let language_precedence = LANGUAGE_PRECEDENCE.lock().unwrap(); diff --git a/src/abbrs.rs b/src/abbrs.rs index fd29e231b..da55221db 100644 --- a/src/abbrs.rs +++ b/src/abbrs.rs @@ -1,15 +1,14 @@ use std::{ collections::HashSet, - sync::{Mutex, MutexGuard}, + sync::{LazyLock, Mutex, MutexGuard}, }; use crate::prelude::*; -use once_cell::sync::Lazy; use crate::parse_constants::SourceRange; use pcre2::utf32::Regex; -static ABBRS: Lazy> = Lazy::new(|| Mutex::new(Default::default())); +static ABBRS: LazyLock> = LazyLock::new(|| Mutex::new(Default::default())); pub fn with_abbrs(cb: impl FnOnce(&AbbreviationSet) -> R) -> R { let abbrs_g = ABBRS.lock().unwrap(); diff --git a/src/builtins/random.rs b/src/builtins/random.rs index 6dd1b12ae..288344780 100644 --- a/src/builtins/random.rs +++ b/src/builtins/random.rs @@ -2,13 +2,12 @@ use crate::util::get_seeded_rng; use crate::wutil; -use once_cell::sync::Lazy; use rand::rngs::SmallRng; use rand::{Rng, RngCore}; -use std::sync::Mutex; +use std::sync::{LazyLock, Mutex}; -static RNG: Lazy> = - Lazy::new(|| Mutex::new(get_seeded_rng(rand::rng().next_u64()))); +static RNG: LazyLock> = + LazyLock::new(|| Mutex::new(get_seeded_rng(rand::rng().next_u64()))); pub fn random(parser: &Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> BuiltinResult { let cmd = argv[0]; diff --git a/src/builtins/test.rs b/src/builtins/test.rs index 0660c8387..7a4bc5b35 100644 --- a/src/builtins/test.rs +++ b/src/builtins/test.rs @@ -10,9 +10,9 @@ mod test_expressions { Error, Options, file_id_for_path, fish_wcswidth, lwstat, waccess, wcstod::wcstod, wcstoi_opts, wstat, }; - use once_cell::sync::Lazy; use std::collections::HashMap; use std::os::unix::prelude::*; + use std::sync::LazyLock; #[derive(Copy, Clone, PartialEq, Eq)] pub(super) enum Token { @@ -182,7 +182,7 @@ fn token_for_string(str: &wstr) -> Token { TOKEN_INFOS.get(str).copied().unwrap_or(Token::Unknown) } - static TOKEN_INFOS: Lazy> = Lazy::new(|| { + static TOKEN_INFOS: LazyLock> = LazyLock::new(|| { let pairs = [ (L!(""), Token::Unknown), (L!("!"), Token::UnaryBoolean(UnaryBooleanToken::Bang)), diff --git a/src/builtins/ulimit.rs b/src/builtins/ulimit.rs index 322d5536e..d0e3868ef 100644 --- a/src/builtins/ulimit.rs +++ b/src/builtins/ulimit.rs @@ -1,9 +1,8 @@ -use std::cmp::Ordering; +use std::{cmp::Ordering, sync::LazyLock}; use libc::{RLIM_INFINITY, c_uint, rlim_t}; use nix::errno::Errno; use nix::sys::resource::Resource as ResourceEnum; -use once_cell::sync::Lazy; use crate::wutil::perror; use fish_fallback::{fish_wcswidth, wcscasecmp}; @@ -434,7 +433,7 @@ fn new( } /// Array of resource_t structs, describing all known resource types. -static RESOURCE_ARR: Lazy> = Lazy::new(|| { +static RESOURCE_ARR: LazyLock> = LazyLock::new(|| { let resources_info = [ ( limits::SBSIZE, diff --git a/src/complete.rs b/src/complete.rs index 7db6b9c1f..cb229421d 100644 --- a/src/complete.rs +++ b/src/complete.rs @@ -4,7 +4,7 @@ mem, ops::{Deref, DerefMut}, sync::{ - Mutex, MutexGuard, + LazyLock, Mutex, MutexGuard, atomic::{self, AtomicUsize}, }, time::{Duration, Instant}, @@ -55,7 +55,6 @@ }; use bitflags::bitflags; use fish_wchar::WExt; -use once_cell::sync::Lazy; // Completion description strings, mostly for different types of files, such as sockets, block // devices, etc. @@ -451,7 +450,7 @@ struct CompletionEntryIndex { /// Completion "wrapper" support. The map goes from wrapping-command to wrapped-command-list. type WrapperMap = HashMap>; -static WRAPPER_MAP: Lazy> = Lazy::new(|| Mutex::new(HashMap::new())); +static WRAPPER_MAP: LazyLock> = LazyLock::new(|| Mutex::new(HashMap::new())); /// Clear the [`CompleteFlags::AUTO_SPACE`] flag, and set [`CompleteFlags::NO_SPACE`] appropriately /// depending on the suffix of the string. @@ -606,8 +605,8 @@ struct Completer<'ctx> { condition_cache: HashMap, } -static COMPLETION_AUTOLOADER: Lazy> = - Lazy::new(|| Mutex::new(Autoload::new(L!("fish_complete_path")))); +static COMPLETION_AUTOLOADER: LazyLock> = + LazyLock::new(|| Mutex::new(Autoload::new(L!("fish_complete_path")))); impl<'ctx> Completer<'ctx> { pub fn new(ctx: &'ctx OperationContext<'ctx>, flags: CompletionRequestOptions) -> Self { diff --git a/src/env/environment.rs b/src/env/environment.rs index e8864c232..47c0c8a9b 100644 --- a/src/env/environment.rs +++ b/src/env/environment.rs @@ -28,13 +28,13 @@ use crate::wutil::{fish_wcstol, wgetcwd}; use libc::{c_int, uid_t}; -use once_cell::sync::{Lazy, OnceCell}; +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; +use std::sync::{Arc, LazyLock}; /// 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); @@ -591,7 +591,7 @@ fn setup_user(global_exported_mode: EnvSetMode, vars: &EnvStack) { } } -pub(crate) static FALLBACK_PATH: Lazy<&[WString]> = Lazy::new(|| { +pub(crate) static FALLBACK_PATH: LazyLock<&[WString]> = LazyLock::new(|| { // _CS_PATH: colon-separated paths to find POSIX utilities. Same as USER_CS_PATH. let cs_path = libc::_CS_PATH; diff --git a/src/env/environment_impl.rs b/src/env/environment_impl.rs index fedc46f85..387bbf336 100644 --- a/src/env/environment_impl.rs +++ b/src/env/environment_impl.rs @@ -15,13 +15,13 @@ use crate::threads::{is_forked_child, is_main_thread}; use crate::wutil::fish_wcstol_radix; -use once_cell::sync::Lazy; use std::cell::{RefCell, UnsafeCell}; use std::collections::HashSet; use std::ffi::CString; use std::marker::PhantomData; use std::mem; use std::ops::{Deref, DerefMut}; +use std::sync::LazyLock; #[cfg(not(target_has_atomic = "64"))] use portable_atomic::AtomicU64; @@ -294,7 +294,7 @@ fn next(&mut self) -> Option { } } -static GLOBAL_NODE: Lazy = Lazy::new(|| EnvNodeRef::new(false, None)); +static GLOBAL_NODE: LazyLock = LazyLock::new(|| EnvNodeRef::new(false, None)); /// Recursive helper to snapshot a series of nodes. fn copy_node_chain(node: &EnvNodeRef) -> EnvNodeRef { diff --git a/src/env_dispatch.rs b/src/env_dispatch.rs index b6f01aa34..7225c9f7e 100644 --- a/src/env_dispatch.rs +++ b/src/env_dispatch.rs @@ -231,6 +231,7 @@ pub fn env_dispatch_var_change(milieu: VarChangeMilieu, key: &wstr, vars: &EnvSt let suppress_repaint = milieu.is_repainting || !milieu.global_or_universal; // We want to ignore variable changes until the dispatch table is explicitly initialized. + // TODO(MSRV>=1.94): Use std::sync::LazyLock. (LazyLock::get is stabilized in Rust 1.94) if let Some(dispatch_table) = Lazy::get(&VAR_DISPATCH_TABLE) { dispatch_table.dispatch(key, vars, suppress_repaint); } diff --git a/src/function.rs b/src/function.rs index cb805ee3e..c26b1e722 100644 --- a/src/function.rs +++ b/src/function.rs @@ -14,10 +14,9 @@ use crate::parser_keywords::parser_keywords_is_reserved; use crate::prelude::*; use crate::wutil::dir_iter::DirIter; -use once_cell::sync::Lazy; use std::collections::{HashMap, HashSet}; use std::num::NonZeroU32; -use std::sync::{Arc, Mutex}; +use std::sync::{Arc, LazyLock, Mutex}; #[derive(Clone)] pub struct FunctionProperties { @@ -100,7 +99,7 @@ fn allow_autoload(&self, name: &wstr) -> bool { } /// The big set of all functions. -static FUNCTION_SET: Lazy> = Lazy::new(|| { +static FUNCTION_SET: LazyLock> = LazyLock::new(|| { Mutex::new(FunctionSet { funcs: HashMap::new(), autoload_tombstones: HashSet::new(), diff --git a/src/input.rs b/src/input.rs index a48396414..5b4981104 100644 --- a/src/input.rs +++ b/src/input.rs @@ -10,10 +10,9 @@ use crate::prelude::*; use crate::reader::{Reader, reader_reset_interrupted}; use crate::threads::assert_is_main_thread; -use once_cell::sync::Lazy; use std::mem; use std::sync::{ - Mutex, MutexGuard, + LazyLock, Mutex, MutexGuard, atomic::{AtomicU32, Ordering}, }; @@ -228,8 +227,8 @@ pub struct InputMappingSet { /// Access the singleton input mapping set. pub fn input_mappings() -> MutexGuard<'static, InputMappingSet> { - static INPUT_MAPPINGS: Lazy> = - Lazy::new(|| Mutex::new(InputMappingSet::default())); + static INPUT_MAPPINGS: LazyLock> = + LazyLock::new(|| Mutex::new(InputMappingSet::default())); INPUT_MAPPINGS.lock().unwrap() } diff --git a/src/io.rs b/src/io.rs index 90aeb12c2..cfdfd5422 100644 --- a/src/io.rs +++ b/src/io.rs @@ -18,11 +18,10 @@ use libc::{EAGAIN, EINTR, ENOENT, ENOTDIR, EPIPE, EWOULDBLOCK, STDOUT_FILENO}; use nix::fcntl::OFlag; use nix::sys::stat::Mode; -use once_cell::sync::Lazy; use std::fs::File; use std::io; use std::os::fd::{AsFd, AsRawFd, BorrowedFd, OwnedFd, RawFd}; -use std::sync::{Arc, Mutex, MutexGuard}; +use std::sync::{Arc, LazyLock, Mutex, MutexGuard}; /// separated_buffer_t represents a buffer of output from commands, prepared to be turned into a /// variable. For example, command substitutions output into one of these. Most commands just @@ -935,7 +934,7 @@ pub fn is_stdin_closed(&self) -> bool { const OPEN_MASK: Mode = Mode::from_bits_truncate(0o666); /// Provide the fd monitor used for background fillthread operations. -static FD_MONITOR: Lazy = Lazy::new(FdMonitor::new); +static FD_MONITOR: LazyLock = LazyLock::new(FdMonitor::new); pub fn fd_monitor() -> &'static FdMonitor { &FD_MONITOR diff --git a/src/kill.rs b/src/kill.rs index 8e82e2b9f..a888a4dd9 100644 --- a/src/kill.rs +++ b/src/kill.rs @@ -3,15 +3,14 @@ //! Works like the killring in emacs and readline. The killring is cut and paste with a memory of //! previous cuts. -use once_cell::sync::Lazy; use std::collections::VecDeque; -use std::sync::Mutex; +use std::sync::{LazyLock, Mutex}; use crate::prelude::*; struct KillRing(VecDeque); -static KILL_RING: Lazy> = Lazy::new(|| Mutex::new(KillRing::new())); +static KILL_RING: LazyLock> = LazyLock::new(|| Mutex::new(KillRing::new())); impl KillRing { /// Create a new killring. diff --git a/src/localization/gettext.rs b/src/localization/gettext.rs index e8435c4ba..c75f6c1ec 100644 --- a/src/localization/gettext.rs +++ b/src/localization/gettext.rs @@ -1,6 +1,5 @@ use fish_wchar::{L, WString, wstr}; -use once_cell::sync::Lazy; -use std::sync::Mutex; +use std::sync::{LazyLock, Mutex}; /// Use this function to localize a message. /// The [`MaybeStatic`] wrapper type allows avoiding allocating and leaking a new [`wstr`] when no @@ -17,8 +16,8 @@ fn gettext(message: MaybeStatic) -> &'static wstr { MaybeStatic::Static(s) => s, MaybeStatic::Local(s) => s, }; - static MESSAGE_TO_NARROW: Lazy>> = - Lazy::new(|| Mutex::new(HashMap::default())); + static MESSAGE_TO_NARROW: LazyLock>> = + LazyLock::new(|| Mutex::new(HashMap::default())); let mut message_to_narrow = MESSAGE_TO_NARROW.lock().unwrap(); if !message_to_narrow.contains_key(message_wstr) { let message_wstr: &'static wstr = match message { @@ -38,8 +37,8 @@ fn gettext(message: MaybeStatic) -> &'static wstr { #[cfg(feature = "localize-messages")] { if let Some(localized_str) = fish_gettext::gettext(message_str) { - static LOCALIZATION_TO_WIDE: Lazy>> = - Lazy::new(|| Mutex::new(HashMap::default())); + static LOCALIZATION_TO_WIDE: LazyLock>> = + LazyLock::new(|| Mutex::new(HashMap::default())); let mut localizations_to_wide = LOCALIZATION_TO_WIDE.lock().unwrap(); if !localizations_to_wide.contains_key(localized_str) { let localization_wstr = diff --git a/src/localization/settings.rs b/src/localization/settings.rs index 92856e9ee..901c13fb1 100644 --- a/src/localization/settings.rs +++ b/src/localization/settings.rs @@ -1,9 +1,8 @@ use super::{localizable_consts, localizable_string, wgettext, wgettext_fmt}; use crate::env::{EnvStack, Environment}; use fish_wchar::{L, WString, wstr}; -use once_cell::sync::Lazy; use std::collections::{HashMap, HashSet}; -use std::sync::Mutex; +use std::sync::{LazyLock, Mutex}; #[derive(PartialEq, Eq, Clone, Copy)] enum LanguagePrecedenceOrigin { @@ -318,8 +317,8 @@ fn update_precedence<'a, 'b, 'c: 'a + 'b, LocalizationLanguage: Copy + 'a>( /// /// This struct should be updated when the relevant variables change or `status language` is used /// to modify the localization state. -static LOCALIZATION_STATE: Lazy> = - Lazy::new(|| Mutex::new(LocalizationState::new())); +static LOCALIZATION_STATE: LazyLock> = + LazyLock::new(|| Mutex::new(LocalizationState::new())); /// Call this when one of `LANGUAGE`, `LC_ALL`, `LC_MESSAGES`, `LANG` changes. /// Updates internal state such that the correct localizations will be used in subsequent diff --git a/src/path.rs b/src/path.rs index 5e1176866..cfe6f9f38 100644 --- a/src/path.rs +++ b/src/path.rs @@ -10,11 +10,11 @@ use crate::wutil::{normalize_path, path_normalize_for_cd, waccess, wdirname, wstat}; use errno::{Errno, errno, set_errno}; use libc::{EACCES, ENOENT, ENOTDIR, F_OK, X_OK}; -use once_cell::sync::Lazy; use std::ffi::OsStr; use std::io::ErrorKind; use std::mem::MaybeUninit; use std::os::unix::prelude::*; +use std::sync::LazyLock; /// Returns the user configuration directory for fish. If the directory or one of its parents /// doesn't exist, they are first created. @@ -729,20 +729,20 @@ pub fn path_remoteness(path: &wstr) -> DirRemoteness { } fn get_data_directory() -> &'static BaseDirectory { - static DIR: Lazy = - Lazy::new(|| make_base_directory(L!("XDG_DATA_HOME"), L!("/.local/share/fish"))); + static DIR: LazyLock = + LazyLock::new(|| make_base_directory(L!("XDG_DATA_HOME"), L!("/.local/share/fish"))); &DIR } fn get_cache_directory() -> &'static BaseDirectory { - static DIR: Lazy = - Lazy::new(|| make_base_directory(L!("XDG_CACHE_HOME"), L!("/.cache/fish"))); + static DIR: LazyLock = + LazyLock::new(|| make_base_directory(L!("XDG_CACHE_HOME"), L!("/.cache/fish"))); &DIR } fn get_config_directory() -> &'static BaseDirectory { - static DIR: Lazy = - Lazy::new(|| make_base_directory(L!("XDG_CONFIG_HOME"), L!("/.config/fish"))); + static DIR: LazyLock = + LazyLock::new(|| make_base_directory(L!("XDG_CONFIG_HOME"), L!("/.config/fish"))); &DIR } diff --git a/src/proc.rs b/src/proc.rs index c2864c9f5..8fb1acf41 100644 --- a/src/proc.rs +++ b/src/proc.rs @@ -28,7 +28,6 @@ SIGINT, SIGKILL, SIGPIPE, SIGQUIT, SIGSEGV, SIGSYS, SIGTTOU, STDOUT_FILENO, WCONTINUED, WEXITSTATUS, WIFCONTINUED, WIFEXITED, WIFSIGNALED, WIFSTOPPED, WNOHANG, WTERMSIG, WUNTRACED, }; -use once_cell::sync::Lazy; #[cfg(not(target_has_atomic = "64"))] use portable_atomic::AtomicU64; use std::cell::{Cell, Ref, RefCell, RefMut}; @@ -40,7 +39,7 @@ #[cfg(target_has_atomic = "64")] use std::sync::atomic::AtomicU64; use std::sync::atomic::{AtomicU8, Ordering}; -use std::sync::{Arc, Mutex, OnceLock}; +use std::sync::{Arc, LazyLock, Mutex, OnceLock}; /// Types of processes. #[derive(Default)] @@ -1615,8 +1614,8 @@ fn process_clean_after_marking(parser: &Parser, interactive: bool) -> bool { pub fn have_proc_stat() -> bool { // Check for /proc/self/stat to see if we are running with Linux-style procfs. - static HAVE_PROC_STAT_RESULT: Lazy = - Lazy::new(|| fs::metadata("/proc/self/stat").is_ok()); + static HAVE_PROC_STAT_RESULT: LazyLock = + LazyLock::new(|| fs::metadata("/proc/self/stat").is_ok()); *HAVE_PROC_STAT_RESULT } diff --git a/src/reader/reader.rs b/src/reader/reader.rs index 4ce369730..b34878a7b 100644 --- a/src/reader/reader.rs +++ b/src/reader/reader.rs @@ -24,7 +24,6 @@ }; use nix::fcntl::OFlag; use nix::sys::stat::Mode; -use once_cell::sync::Lazy; #[cfg(not(target_has_atomic = "64"))] use portable_atomic::AtomicU64; use std::borrow::Cow; @@ -43,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, Mutex, MutexGuard}; +use std::sync::{Arc, LazyLock, Mutex, MutexGuard}; use std::time::{Duration, Instant}; use errno::{Errno, errno}; @@ -175,8 +174,8 @@ enum ExitState { static EXIT_STATE: AtomicU8 = AtomicU8::new(ExitState::None as u8); -pub static SHELL_MODES: Lazy> = - Lazy::new(|| Mutex::new(unsafe { std::mem::zeroed() })); +pub static SHELL_MODES: LazyLock> = + LazyLock::new(|| Mutex::new(unsafe { std::mem::zeroed() })); /// The valid terminal modes on startup. /// Warning: this is read from the SIGTERM handler! Hence the raw global. @@ -184,8 +183,8 @@ enum ExitState { once_cell::sync::OnceCell::new(); /// Mode we use to execute programs. -static TTY_MODES_FOR_EXTERNAL_CMDS: Lazy> = - Lazy::new(|| Mutex::new(unsafe { std::mem::zeroed() })); +static TTY_MODES_FOR_EXTERNAL_CMDS: LazyLock> = + LazyLock::new(|| Mutex::new(unsafe { std::mem::zeroed() })); static RUN_COUNT: AtomicU64 = AtomicU64::new(0); diff --git a/src/signal.rs b/src/signal.rs index f8cef5996..b0f0fabd7 100644 --- a/src/signal.rs +++ b/src/signal.rs @@ -11,8 +11,10 @@ use crate::tty_handoff::{safe_deactivate_tty_protocols, safe_mark_tty_invalid}; use crate::wutil::{fish_wcstoi, perror}; use errno::{errno, set_errno}; -use once_cell::sync::Lazy; -use std::sync::atomic::{AtomicI32, Ordering}; +use std::sync::{ + LazyLock, + atomic::{AtomicI32, Ordering}, +}; /// Store the "main" pid. This allows us to reliably determine if we are in a forked child. static MAIN_PID: AtomicI32 = AtomicI32::new(0); @@ -278,7 +280,7 @@ pub fn signal_handle(sig: Signal) { sigaction(sig, &act, std::ptr::null_mut()); } -pub static signals_to_default: Lazy = Lazy::new(|| { +pub static signals_to_default: LazyLock = LazyLock::new(|| { let mut set = MaybeUninit::uninit(); unsafe { libc::sigemptyset(set.as_mut_ptr()) }; for data in SIGNAL_TABLE.iter() { diff --git a/src/wildcard.rs b/src/wildcard.rs index cfa109503..769b2cc88 100644 --- a/src/wildcard.rs +++ b/src/wildcard.rs @@ -2,10 +2,10 @@ use fish_common::char_offset; use libc::X_OK; -use once_cell::sync::Lazy; use std::cmp::Ordering; use std::collections::HashSet; use std::os::unix::fs::MetadataExt; +use std::sync::LazyLock; use crate::common::{ UnescapeFlags, UnescapeStringStyle, WILDCARD_RESERVED_BASE, WSL, @@ -375,12 +375,12 @@ fn wildcard_test_flags_then_complete( // regular file *excludes* broken links - we have no use for them as commands. let is_regular_file = entry.check_type().is_some_and(|x| x == DirEntryType::Reg); - let is_executable = Lazy::new(|| is_regular_file && waccess(filepath, X_OK) == 0); + let is_executable = LazyLock::new(|| is_regular_file && waccess(filepath, X_OK) == 0); if executables_only && !*is_executable { return false; } - let filepath_stat = Lazy::new(|| lwstat(filepath)); + let filepath_stat = LazyLock::new(|| lwstat(filepath)); // For executables on Cygwin, prefer the name without the .exe, to match // better with Unix names, but only if there isn't also a file without that