about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-03-03 23:01:37 +0000
committerbors <bors@rust-lang.org>2024-03-03 23:01:37 +0000
commitaceeb54b7562754726bc24a1aaa235448c1867e7 (patch)
treec156c8c2b66f9f89bb02aac78a68a9071257ca49
parent30642113b218f625de8df0e388c720f9a41641be (diff)
parent08459b4daea3f691215d05f84df190cc4071c20c (diff)
Auto merge of #12405 - PartiallyTyped:12404, r=blyxyas
Added msrv to threadlocal initializer check

closes: #12404
changelog:[`thread_local_initializer_can_be_made_const`]: Check for MSRV (>= 1.59) before processing.
-rw-r--r--clippy_config/src/msrvs.rs1
-rw-r--r--clippy_lints/src/thread_local_initializer_can_be_made_const.rs5
-rw-r--r--tests/ui/thread_local_initializer_can_be_made_const.fixed7
-rw-r--r--tests/ui/thread_local_initializer_can_be_made_const.rs7
4 files changed, 18 insertions, 2 deletions
diff --git a/clippy_config/src/msrvs.rs b/clippy_config/src/msrvs.rs
index f4389db627d..a8a32f7ed20 100644
--- a/clippy_config/src/msrvs.rs
+++ b/clippy_config/src/msrvs.rs
@@ -24,6 +24,7 @@ msrv_aliases! {
     1,68,0 { PATH_MAIN_SEPARATOR_STR }
     1,65,0 { LET_ELSE, POINTER_CAST_CONSTNESS }
     1,62,0 { BOOL_THEN_SOME, DEFAULT_ENUM_ATTRIBUTE }
+    1,59,0 { THREAD_LOCAL_INITIALIZER_CAN_BE_MADE_CONST }
     1,58,0 { FORMAT_ARGS_CAPTURE, PATTERN_TRAIT_CHAR_ARRAY }
     1,55,0 { SEEK_REWIND }
     1,54,0 { INTO_KEYS }
diff --git a/clippy_lints/src/thread_local_initializer_can_be_made_const.rs b/clippy_lints/src/thread_local_initializer_can_be_made_const.rs
index 2dac5ff0c3a..1af3733ebfa 100644
--- a/clippy_lints/src/thread_local_initializer_can_be_made_const.rs
+++ b/clippy_lints/src/thread_local_initializer_can_be_made_const.rs
@@ -1,4 +1,4 @@
-use clippy_config::msrvs::Msrv;
+use clippy_config::msrvs::{self, Msrv};
 use clippy_utils::diagnostics::span_lint_and_sugg;
 use clippy_utils::qualify_min_const_fn::is_min_const_fn;
 use clippy_utils::source::snippet;
@@ -92,7 +92,8 @@ impl<'tcx> LateLintPass<'tcx> for ThreadLocalInitializerCanBeMadeConst {
         local_defid: rustc_span::def_id::LocalDefId,
     ) {
         let defid = local_defid.to_def_id();
-        if is_thread_local_initializer(cx, fn_kind, span).unwrap_or(false)
+        if self.msrv.meets(msrvs::THREAD_LOCAL_INITIALIZER_CAN_BE_MADE_CONST)
+            && is_thread_local_initializer(cx, fn_kind, span).unwrap_or(false)
             // Some implementations of `thread_local!` include an initializer fn.
             // In the case of a const initializer, the init fn is also const,
             // so we can skip the lint in that case. This occurs only on some
diff --git a/tests/ui/thread_local_initializer_can_be_made_const.fixed b/tests/ui/thread_local_initializer_can_be_made_const.fixed
index 1a2c5ffc56f..a6ed59d49c5 100644
--- a/tests/ui/thread_local_initializer_can_be_made_const.fixed
+++ b/tests/ui/thread_local_initializer_can_be_made_const.fixed
@@ -35,3 +35,10 @@ fn main() {
         //~^ ERROR: initializer for `thread_local` value can be made `const`
     }
 }
+
+#[clippy::msrv = "1.58"]
+fn f() {
+    thread_local! {
+        static TLS: i32 = 1;
+    }
+}
diff --git a/tests/ui/thread_local_initializer_can_be_made_const.rs b/tests/ui/thread_local_initializer_can_be_made_const.rs
index 7fb00cd1342..3f0159c5806 100644
--- a/tests/ui/thread_local_initializer_can_be_made_const.rs
+++ b/tests/ui/thread_local_initializer_can_be_made_const.rs
@@ -35,3 +35,10 @@ fn main() {
         //~^ ERROR: initializer for `thread_local` value can be made `const`
     }
 }
+
+#[clippy::msrv = "1.58"]
+fn f() {
+    thread_local! {
+        static TLS: i32 = 1;
+    }
+}