Skip to content

Commit f91386e

Browse files
PartiallyUntypedflip1995
authored andcommitted
Added msrv to threadlocal initializer
1 parent 3aab9a6 commit f91386e

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

src/tools/clippy/clippy_config/src/msrvs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ msrv_aliases! {
2121
1,68,0 { PATH_MAIN_SEPARATOR_STR }
2222
1,65,0 { LET_ELSE, POINTER_CAST_CONSTNESS }
2323
1,62,0 { BOOL_THEN_SOME, DEFAULT_ENUM_ATTRIBUTE }
24+
1,59,0 { THREAD_LOCAL_INITIALIZER_CAN_BE_MADE_CONST }
2425
1,58,0 { FORMAT_ARGS_CAPTURE, PATTERN_TRAIT_CHAR_ARRAY }
2526
1,55,0 { SEEK_REWIND }
2627
1,54,0 { INTO_KEYS }

src/tools/clippy/clippy_lints/src/thread_local_initializer_can_be_made_const.rs

Lines changed: 3 additions & 2 deletions
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

src/tools/clippy/tests/ui/thread_local_initializer_can_be_made_const.fixed

Lines changed: 7 additions & 0 deletions
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+
}

src/tools/clippy/tests/ui/thread_local_initializer_can_be_made_const.rs

Lines changed: 7 additions & 0 deletions
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)