about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-06-25 02:40:30 +0000
committerbors <bors@rust-lang.org>2022-06-25 02:40:30 +0000
commit93ebd0e2db0e7c316cca3d35b077d19a79b4e7b1 (patch)
tree81f04b9435b833403dc68a522451cb33c5ef2558
parente17864e2ffd4244906a689705d8e2ce7ffac6d6b (diff)
parenta9215d90c8c576e5f2afd1ef69c6f172229e021e (diff)
downloadrust-93ebd0e2db0e7c316cca3d35b077d19a79b4e7b1.tar.gz
rust-93ebd0e2db0e7c316cca3d35b077d19a79b4e7b1.zip
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`
-rw-r--r--clippy_lints/src/non_copy_const.rs13
-rw-r--r--tests/ui/declare_interior_mutable_const/others.rs5
2 files changed, 15 insertions, 3 deletions
diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs
index 1727275a4e0..a1ef32ae608 100644
--- a/clippy_lints/src/non_copy_const.rs
+++ b/clippy_lints/src/non_copy_const.rs
@@ -6,6 +6,7 @@ use std::ptr;
 
 use clippy_utils::diagnostics::span_lint_and_then;
 use clippy_utils::in_constant;
+use clippy_utils::macros::macro_backtrace;
 use if_chain::if_chain;
 use rustc_hir::def::{DefKind, Res};
 use rustc_hir::def_id::DefId;
@@ -18,7 +19,7 @@ use rustc_middle::mir::interpret::{ConstValue, ErrorHandled};
 use rustc_middle::ty::adjustment::Adjust;
 use rustc_middle::ty::{self, Ty};
 use rustc_session::{declare_lint_pass, declare_tool_lint};
-use rustc_span::{InnerSpan, Span, DUMMY_SP};
+use rustc_span::{sym, InnerSpan, Span, DUMMY_SP};
 use rustc_typeck::hir_ty_to_ty;
 
 // FIXME: this is a correctness problem but there's no suitable
@@ -250,8 +251,14 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst {
     fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx Item<'_>) {
         if let ItemKind::Const(hir_ty, body_id) = it.kind {
             let ty = hir_ty_to_ty(cx.tcx, hir_ty);
-
-            if is_unfrozen(cx, ty) && is_value_unfrozen_poly(cx, body_id, ty) {
+            if !macro_backtrace(it.span).last().map_or(false, |macro_call| {
+                matches!(
+                    cx.tcx.get_diagnostic_name(macro_call.def_id),
+                    Some(sym::thread_local_macro)
+                )
+            }) && is_unfrozen(cx, ty)
+                && is_value_unfrozen_poly(cx, body_id, ty)
+            {
                 lint(cx, Source::Item { item: it.span });
             }
         }
diff --git a/tests/ui/declare_interior_mutable_const/others.rs b/tests/ui/declare_interior_mutable_const/others.rs
index 48c5e9537d6..62af545db50 100644
--- a/tests/ui/declare_interior_mutable_const/others.rs
+++ b/tests/ui/declare_interior_mutable_const/others.rs
@@ -31,4 +31,9 @@ const NO_ANN: &dyn Display = &70;
 static STATIC_TUPLE: (AtomicUsize, String) = (ATOMIC, STRING);
 //^ there should be no lints on this line
 
+// issue #8493
+thread_local! {
+    static THREAD_LOCAL: Cell<i32> = const { Cell::new(0) };
+}
+
 fn main() {}