[pbs-devel] [PATCH proxmox v2 08/18] use const blocks in thread_local! calls

Maximiliano Sandoval m.sandoval at proxmox.com
Wed Jun 26 14:43:36 CEST 2024


Fixes the clippy warning:

warning: initializer for `thread_local` value can be made `const`
   --> proxmox-router/src/cli/command.rs:221:71
    |
221 |     static HELP_CONTEXT: RefCell<Option<Arc<CommandLineInterface>>> = RefCell::new(None);
    |                                                                       ^^^^^^^^^^^^^^^^^^ help: replace with: `const { RefCell::new(None) }`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#thread_local_initializer_can_be_made_const
    = note: `#[warn(clippy::thread_local_initializer_can_be_made_const)]` on by default

Signed-off-by: Maximiliano Sandoval <m.sandoval at proxmox.com>
---
 proxmox-api-macro/src/lib.rs      | 2 +-
 proxmox-router/src/cli/command.rs | 2 +-
 proxmox-schema/src/de/mod.rs      | 2 +-
 proxmox-schema/src/de/verify.rs   | 4 ++--
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/proxmox-api-macro/src/lib.rs b/proxmox-api-macro/src/lib.rs
index 9888b76c..3c34b48b 100644
--- a/proxmox-api-macro/src/lib.rs
+++ b/proxmox-api-macro/src/lib.rs
@@ -313,7 +313,7 @@ pub fn derive_updater_type(item: TokenStream_1) -> TokenStream_1 {
     .into()
 }
 
-thread_local!(static NON_FATAL_ERRORS: RefCell<Option<TokenStream>> = RefCell::new(None));
+thread_local!(static NON_FATAL_ERRORS: RefCell<Option<TokenStream>> = const { RefCell::new(None) });
 
 /// The local error TLS must be freed at the end of a macro as any leftover `TokenStream` (even an
 /// empty one) will just panic between different runs as the multiple source files are handled by
diff --git a/proxmox-router/src/cli/command.rs b/proxmox-router/src/cli/command.rs
index a97c9d48..fca05e32 100644
--- a/proxmox-router/src/cli/command.rs
+++ b/proxmox-router/src/cli/command.rs
@@ -218,7 +218,7 @@ const API_METHOD_COMMAND_HELP: ApiMethod = ApiMethod::new(
 );
 
 std::thread_local! {
-    static HELP_CONTEXT: RefCell<Option<Arc<CommandLineInterface>>> = RefCell::new(None);
+    static HELP_CONTEXT: RefCell<Option<Arc<CommandLineInterface>>> = const { RefCell::new(None) };
 }
 
 fn help_command(
diff --git a/proxmox-schema/src/de/mod.rs b/proxmox-schema/src/de/mod.rs
index 09ccfeb3..79fb18e7 100644
--- a/proxmox-schema/src/de/mod.rs
+++ b/proxmox-schema/src/de/mod.rs
@@ -24,7 +24,7 @@ pub use no_schema::{split_list, SplitList};
 // Used to disable calling `check_constraints` on a `StringSchema` if it is being deserialized
 // for a `PropertyString`, which performs its own checking.
 thread_local! {
-    static IN_PROPERTY_STRING: Cell<bool> = Cell::new(false);
+    static IN_PROPERTY_STRING: Cell<bool> = const { Cell::new(false) };
 }
 
 pub(crate) struct InPropertyStringGuard;
diff --git a/proxmox-schema/src/de/verify.rs b/proxmox-schema/src/de/verify.rs
index 24a14772..615e69cf 100644
--- a/proxmox-schema/src/de/verify.rs
+++ b/proxmox-schema/src/de/verify.rs
@@ -16,8 +16,8 @@ struct VerifyState {
 }
 
 thread_local! {
-    static VERIFY_SCHEMA: RefCell<Option<VerifyState>> = RefCell::new(None);
-    static ERRORS: RefCell<Vec<(String, anyhow::Error)>> = RefCell::new(Vec::new());
+    static VERIFY_SCHEMA: RefCell<Option<VerifyState>> = const { RefCell::new(None) };
+    static ERRORS: RefCell<Vec<(String, anyhow::Error)>> = const { RefCell::new(Vec::new()) };
 }
 
 pub(crate) struct SchemaGuard(Option<VerifyState>);
-- 
2.39.2





More information about the pbs-devel mailing list