about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-09-27 12:58:41 +0000
committerbors <bors@rust-lang.org>2022-09-27 12:58:41 +0000
commitc153bd62377f3c563b9f6e9d6ba7742523c45209 (patch)
treead026858bbfa1d4cec15a6309a143b1b4c125576
parent78dc616a7ae9815ea6bacccbb3aa40d27ed5eb6c (diff)
parentb180d954d600a8c9b98ee31d0298ce1b13b6291f (diff)
downloadrust-c153bd62377f3c563b9f6e9d6ba7742523c45209.tar.gz
rust-c153bd62377f3c563b9f6e9d6ba7742523c45209.zip
Auto merge of #9539 - Jarcho:ice_9445, r=flip1995
Don't lint `*_interior_mutable_const` on unions due to potential ICE.

fixes #9445
cc rust-lang/rust#101113

This started ICE'ing sometime last month due to stricter UB checks. I'm not sure how we could check the value of a union as MIRI doesn't seem to store which field is currently active.

changelog: Don't ICE on const unions containing a `!Freeze` type.
-rw-r--r--clippy_lints/src/non_copy_const.rs3
-rw-r--r--tests/ui/crashes/ice-9445.rs3
2 files changed, 6 insertions, 0 deletions
diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs
index 72c86f28bbc..ea76ce2c573 100644
--- a/clippy_lints/src/non_copy_const.rs
+++ b/clippy_lints/src/non_copy_const.rs
@@ -149,6 +149,9 @@ fn is_value_unfrozen_raw<'tcx>(
             // the fact that we have to dig into every structs to search enums
             // leads us to the point checking `UnsafeCell` directly is the only option.
             ty::Adt(ty_def, ..) if ty_def.is_unsafe_cell() => true,
+            // As of 2022-09-08 miri doesn't track which union field is active so there's no safe way to check the
+            // contained value.
+            ty::Adt(def, ..) if def.is_union() => false,
             ty::Array(..) | ty::Adt(..) | ty::Tuple(..) => {
                 let val = cx.tcx.destructure_mir_constant(cx.param_env, val);
                 val.fields.iter().any(|field| inner(cx, *field))
diff --git a/tests/ui/crashes/ice-9445.rs b/tests/ui/crashes/ice-9445.rs
new file mode 100644
index 00000000000..c67b22f6f8c
--- /dev/null
+++ b/tests/ui/crashes/ice-9445.rs
@@ -0,0 +1,3 @@
+const UNINIT: core::mem::MaybeUninit<core::cell::Cell<&'static ()>> = core::mem::MaybeUninit::uninit();
+
+fn main() {}