Skip to content

Commit 08459b4

Browse files
Added msrv to threadlocal initializer
1 parent 28e11b3 commit 08459b4

4 files changed

+18
-2
lines changed

clippy_config/src/msrvs.rs

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ msrv_aliases! {
2424
1,68,0 { PATH_MAIN_SEPARATOR_STR }
2525
1,65,0 { LET_ELSE, POINTER_CAST_CONSTNESS }
2626
1,62,0 { BOOL_THEN_SOME, DEFAULT_ENUM_ATTRIBUTE }
27+
1,59,0 { THREAD_LOCAL_INITIALIZER_CAN_BE_MADE_CONST }
2728
1,58,0 { FORMAT_ARGS_CAPTURE, PATTERN_TRAIT_CHAR_ARRAY }
2829
1,55,0 { SEEK_REWIND }
2930
1,54,0 { INTO_KEYS }

clippy_lints/src/thread_local_initializer_can_be_made_const.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use clippy_config::msrvs::Msrv;
1+
use clippy_config::msrvs::{self, Msrv};
22
use clippy_utils::diagnostics::span_lint_and_sugg;
33
use clippy_utils::qualify_min_const_fn::is_min_const_fn;
44
use clippy_utils::source::snippet;
@@ -92,7 +92,8 @@ impl<'tcx> LateLintPass<'tcx> for ThreadLocalInitializerCanBeMadeConst {
9292
local_defid: rustc_span::def_id::LocalDefId,
9393
) {
9494
let defid = local_defid.to_def_id();
95-
if is_thread_local_initializer(cx, fn_kind, span).unwrap_or(false)
95+
if self.msrv.meets(msrvs::THREAD_LOCAL_INITIALIZER_CAN_BE_MADE_CONST)
96+
&& is_thread_local_initializer(cx, fn_kind, span).unwrap_or(false)
9697
// Some implementations of `thread_local!` include an initializer fn.
9798
// In the case of a const initializer, the init fn is also const,
9899
// so we can skip the lint in that case. This occurs only on some

tests/ui/thread_local_initializer_can_be_made_const.fixed

+7
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,10 @@ fn main() {
3535
//~^ ERROR: initializer for `thread_local` value can be made `const`
3636
}
3737
}
38+
39+
#[clippy::msrv = "1.58"]
40+
fn f() {
41+
thread_local! {
42+
static TLS: i32 = 1;
43+
}
44+
}

tests/ui/thread_local_initializer_can_be_made_const.rs

+7
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,10 @@ fn main() {
3535
//~^ ERROR: initializer for `thread_local` value can be made `const`
3636
}
3737
}
38+
39+
#[clippy::msrv = "1.58"]
40+
fn f() {
41+
thread_local! {
42+
static TLS: i32 = 1;
43+
}
44+
}

0 commit comments

Comments
 (0)