Skip to content

Commit

Permalink
Auto merge of #12405 - PartiallyTyped:12404, r=blyxyas
Browse files Browse the repository at this point in the history
Added msrv to threadlocal initializer check

closes: #12404
changelog:[`thread_local_initializer_can_be_made_const`]: Check for MSRV (>= 1.59) before processing.
  • Loading branch information
bors committed Mar 3, 2024
2 parents 3064211 + 08459b4 commit aceeb54
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions clippy_config/src/msrvs.rs
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
@@ -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
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
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;
}
}

0 comments on commit aceeb54

Please sign in to comment.