Closed
Description
Summary
thread_local_const_init has been stabilized in 1.59 (rust-lang/rust#91355), but this lint is also triggered for code with MSRV less than 1.59.
Mentioning @partiallytyped, who implemented this lint in #12026.
Lint Name
thread_local_initializer_can_be_made_const
Reproducer
I tried this code:
#![warn(clippy::thread_local_initializer_can_be_made_const)]
#![allow(dead_code)]
#[clippy::msrv = "1.58"]
fn f() {
thread_local! {
static TLS: i32 = 1;
}
}
I saw this happen:
warning: initializer for `thread_local` value can be made `const`
--> src/lib.rs:7:27
|
7 | static TLS: i32 = 1;
| ^ help: replace with: `const { 1 }`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#thread_local_initializer_can_be_made_const
note: the lint level is defined here
--> src/lib.rs:1:9
|
1 | #![warn(clippy::thread_local_initializer_can_be_made_const)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I expected to see this happen: no warning
Version
rustc 1.78.0-nightly (5119208fd 2024-03-02)
binary: rustc
commit-hash: 5119208fd78a77547c705d1695428c88d6791263
commit-date: 2024-03-02
host: aarch64-apple-darwin
release: 1.78.0-nightly
LLVM version: 18.1.0
Additional Labels
No response