From c3927d0ef6b0401eda8d9473926d245c9a17b260 Mon Sep 17 00:00:00 2001 From: David Mak Date: Wed, 30 Oct 2024 12:28:20 +0800 Subject: [PATCH] [ast] Refactor lazy_static to LazyLock It is available in Rust 1.80 and reduces a dependency. --- Cargo.lock | 1 - nac3ast/Cargo.toml | 1 - nac3ast/src/ast_gen.rs | 8 +++----- nac3ast/src/lib.rs | 3 --- 4 files changed, 3 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e9bb8705..333a1056 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -634,7 +634,6 @@ name = "nac3ast" version = "0.1.0" dependencies = [ "fxhash", - "lazy_static", "parking_lot", "string-interner", ] diff --git a/nac3ast/Cargo.toml b/nac3ast/Cargo.toml index 2c78fb42..dc2bd558 100644 --- a/nac3ast/Cargo.toml +++ b/nac3ast/Cargo.toml @@ -10,7 +10,6 @@ constant-optimization = ["fold"] fold = [] [dependencies] -lazy_static = "1.5" parking_lot = "0.12" string-interner = "0.17" fxhash = "0.2" diff --git a/nac3ast/src/ast_gen.rs b/nac3ast/src/ast_gen.rs index a1a62726..d23717dc 100644 --- a/nac3ast/src/ast_gen.rs +++ b/nac3ast/src/ast_gen.rs @@ -5,14 +5,12 @@ pub use crate::location::Location; use fxhash::FxBuildHasher; use parking_lot::{Mutex, MutexGuard}; -use std::{cell::RefCell, collections::HashMap, fmt}; +use std::{cell::RefCell, collections::HashMap, fmt, sync::LazyLock}; use string_interner::{symbol::SymbolU32, DefaultBackend, StringInterner}; pub type Interner = StringInterner; -lazy_static! { - static ref INTERNER: Mutex = - Mutex::new(StringInterner::with_hasher(FxBuildHasher::default())); -} +static INTERNER: LazyLock> = + LazyLock::new(|| Mutex::new(StringInterner::with_hasher(FxBuildHasher::default()))); thread_local! { static LOCAL_INTERNER: RefCell> = RefCell::default(); diff --git a/nac3ast/src/lib.rs b/nac3ast/src/lib.rs index 0bd1dd91..51c703f8 100644 --- a/nac3ast/src/lib.rs +++ b/nac3ast/src/lib.rs @@ -14,9 +14,6 @@ clippy::wildcard_imports )] -#[macro_use] -extern crate lazy_static; - mod ast_gen; mod constant; #[cfg(feature = "fold")]