use const blocks in thread_local! calls

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@proxmox.com>
This commit is contained in:
Maximiliano Sandoval 2024-06-26 14:43:36 +02:00 committed by Wolfgang Bumiller
parent e3602c1943
commit d07a0243f4
4 changed files with 5 additions and 5 deletions

View File

@ -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

View File

@ -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(

View File

@ -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;

View File

@ -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>);