From d2eabced15d872b2ab6ab0bd1a531d52aec7eb6a Mon Sep 17 00:00:00 2001 From: "Victor M. Alvarez" Date: Wed, 28 Jan 2026 09:51:44 +0100 Subject: [PATCH 1/2] fix: warning due to mutation of an interior mutable `const` item with call to `get_or_init` Closes #532 --- lib/src/types/array.rs | 13 +++++++------ lib/src/types/map.rs | 13 +++++++------ lib/src/types/mod.rs | 13 +++++++------ 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/lib/src/types/array.rs b/lib/src/types/array.rs index f7c400225..1f9eb0ab4 100644 --- a/lib/src/types/array.rs +++ b/lib/src/types/array.rs @@ -8,6 +8,10 @@ use crate::symbols::{Symbol, SymbolTable}; use crate::types::{Struct, TypeValue}; use crate::wasm::WasmExport; +thread_local! { + static BUILTIN_METHODS: OnceCell> = OnceCell::new(); +} + #[derive(Serialize, Deserialize)] pub(crate) enum Array { Integers(Vec), @@ -18,13 +22,9 @@ pub(crate) enum Array { } impl Array { - #[allow(clippy::declare_interior_mutable_const)] - const BUILTIN_METHODS: OnceCell> = OnceCell::new(); - pub fn builtin_methods() -> Rc { - #[allow(clippy::borrow_interior_mutable_const)] - Self::BUILTIN_METHODS - .get_or_init(|| { + BUILTIN_METHODS.with(|cell| { + cell.get_or_init(|| { let mut s = SymbolTable::new(); for (name, func) in WasmExport::get_methods("Array") { s.insert(name, Symbol::Func(Rc::new(func))); @@ -32,6 +32,7 @@ impl Array { Rc::new(s) }) .clone() + }) } pub fn deputy(&self) -> TypeValue { diff --git a/lib/src/types/map.rs b/lib/src/types/map.rs index de788b322..d0ad6068b 100644 --- a/lib/src/types/map.rs +++ b/lib/src/types/map.rs @@ -8,6 +8,10 @@ use crate::symbols::{Symbol, SymbolTable}; use crate::types::TypeValue; use crate::wasm::WasmExport; +thread_local! { + static BUILTIN_METHODS: OnceCell> = OnceCell::new(); +} + #[derive(Serialize, Deserialize)] pub(crate) enum Map { /// A map that has integer keys. @@ -31,13 +35,9 @@ pub(crate) enum Map { } impl Map { - #[allow(clippy::declare_interior_mutable_const)] - const BUILTIN_METHODS: OnceCell> = OnceCell::new(); - pub fn builtin_methods() -> Rc { - #[allow(clippy::borrow_interior_mutable_const)] - Self::BUILTIN_METHODS - .get_or_init(|| { + BUILTIN_METHODS.with(|cell| { + cell.get_or_init(|| { let mut s = SymbolTable::new(); for (name, func) in WasmExport::get_methods("Map") { s.insert(name, Symbol::Func(Rc::new(func))); @@ -45,6 +45,7 @@ impl Map { Rc::new(s) }) .clone() + }) } pub fn deputy(&self) -> TypeValue { diff --git a/lib/src/types/mod.rs b/lib/src/types/mod.rs index 38b07dfc9..7fa821bd8 100644 --- a/lib/src/types/mod.rs +++ b/lib/src/types/mod.rs @@ -17,6 +17,10 @@ pub(crate) use func::*; pub(crate) use map::*; pub(crate) use structure::*; +thread_local! { + static STRING_BUILTIN_METHODS: OnceCell> = OnceCell::new(); +} + mod array; mod func; mod map; @@ -310,13 +314,9 @@ impl TypeValue { } } - #[allow(clippy::declare_interior_mutable_const)] - const STRING_BUILTIN_METHODS: OnceCell> = OnceCell::new(); - fn string_builtin_methods() -> Rc { - #[allow(clippy::borrow_interior_mutable_const)] - Self::STRING_BUILTIN_METHODS - .get_or_init(|| { + STRING_BUILTIN_METHODS.with(|cell| { + cell.get_or_init(|| { let mut s = SymbolTable::new(); for (name, func) in WasmExport::get_methods("RuntimeString") { s.insert(name, Symbol::Func(Rc::new(func))); @@ -324,6 +324,7 @@ impl TypeValue { Rc::new(s) }) .clone() + }) } /// Returns the symbol table associated to this [`TypeValue`]. From 2d91e7dc10c5711b3f25142a964162b773302d38 Mon Sep 17 00:00:00 2001 From: "Victor M. Alvarez" Date: Wed, 28 Jan 2026 10:15:20 +0100 Subject: [PATCH 2/2] style: fix clippy warning. --- lib/src/types/array.rs | 2 +- lib/src/types/map.rs | 2 +- lib/src/types/mod.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/src/types/array.rs b/lib/src/types/array.rs index 1f9eb0ab4..839ce6ba7 100644 --- a/lib/src/types/array.rs +++ b/lib/src/types/array.rs @@ -9,7 +9,7 @@ use crate::types::{Struct, TypeValue}; use crate::wasm::WasmExport; thread_local! { - static BUILTIN_METHODS: OnceCell> = OnceCell::new(); + static BUILTIN_METHODS: OnceCell> = const { OnceCell::new() }; } #[derive(Serialize, Deserialize)] diff --git a/lib/src/types/map.rs b/lib/src/types/map.rs index d0ad6068b..4253f880a 100644 --- a/lib/src/types/map.rs +++ b/lib/src/types/map.rs @@ -9,7 +9,7 @@ use crate::types::TypeValue; use crate::wasm::WasmExport; thread_local! { - static BUILTIN_METHODS: OnceCell> = OnceCell::new(); + static BUILTIN_METHODS: OnceCell> = const { OnceCell::new() }; } #[derive(Serialize, Deserialize)] diff --git a/lib/src/types/mod.rs b/lib/src/types/mod.rs index 7fa821bd8..f62c7be45 100644 --- a/lib/src/types/mod.rs +++ b/lib/src/types/mod.rs @@ -18,7 +18,7 @@ pub(crate) use map::*; pub(crate) use structure::*; thread_local! { - static STRING_BUILTIN_METHODS: OnceCell> = OnceCell::new(); + static STRING_BUILTIN_METHODS: OnceCell> = const { OnceCell::new() }; } mod array;