Skip to content

Commit 93ebd0e

Browse files
committed
Auto merge of #9015 - kyoto7250:issue_8493, r=Jarcho
ignore item in `thread_local!` macro close #8493 This PR ignores `thread_local` macro in `declare_interior_mutable_const`. changelog: ignore `thread_local!` macro in `declare_interior_mutable_const`
2 parents e17864e + a9215d9 commit 93ebd0e

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

clippy_lints/src/non_copy_const.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::ptr;
66

77
use clippy_utils::diagnostics::span_lint_and_then;
88
use clippy_utils::in_constant;
9+
use clippy_utils::macros::macro_backtrace;
910
use if_chain::if_chain;
1011
use rustc_hir::def::{DefKind, Res};
1112
use rustc_hir::def_id::DefId;
@@ -18,7 +19,7 @@ use rustc_middle::mir::interpret::{ConstValue, ErrorHandled};
1819
use rustc_middle::ty::adjustment::Adjust;
1920
use rustc_middle::ty::{self, Ty};
2021
use rustc_session::{declare_lint_pass, declare_tool_lint};
21-
use rustc_span::{InnerSpan, Span, DUMMY_SP};
22+
use rustc_span::{sym, InnerSpan, Span, DUMMY_SP};
2223
use rustc_typeck::hir_ty_to_ty;
2324

2425
// FIXME: this is a correctness problem but there's no suitable
@@ -250,8 +251,14 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst {
250251
fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx Item<'_>) {
251252
if let ItemKind::Const(hir_ty, body_id) = it.kind {
252253
let ty = hir_ty_to_ty(cx.tcx, hir_ty);
253-
254-
if is_unfrozen(cx, ty) && is_value_unfrozen_poly(cx, body_id, ty) {
254+
if !macro_backtrace(it.span).last().map_or(false, |macro_call| {
255+
matches!(
256+
cx.tcx.get_diagnostic_name(macro_call.def_id),
257+
Some(sym::thread_local_macro)
258+
)
259+
}) && is_unfrozen(cx, ty)
260+
&& is_value_unfrozen_poly(cx, body_id, ty)
261+
{
255262
lint(cx, Source::Item { item: it.span });
256263
}
257264
}

tests/ui/declare_interior_mutable_const/others.rs

+5
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,9 @@ const NO_ANN: &dyn Display = &70;
3131
static STATIC_TUPLE: (AtomicUsize, String) = (ATOMIC, STRING);
3232
//^ there should be no lints on this line
3333

34+
// issue #8493
35+
thread_local! {
36+
static THREAD_LOCAL: Cell<i32> = const { Cell::new(0) };
37+
}
38+
3439
fn main() {}

0 commit comments

Comments
 (0)