Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clippy_config/src/msrvs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions tests/ui/thread_local_initializer_can_be_made_const.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
7 changes: 7 additions & 0 deletions tests/ui/thread_local_initializer_can_be_made_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}