From b180d954d600a8c9b98ee31d0298ce1b13b6291f Mon Sep 17 00:00:00 2001 From: Jason Newcomb Date: Sun, 25 Sep 2022 17:37:56 -0400 Subject: [PATCH] Don't lint `*_interior_mutable_const` on unions due to potential ICE. --- clippy_lints/src/non_copy_const.rs | 3 +++ tests/ui/crashes/ice-9445.rs | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 tests/ui/crashes/ice-9445.rs diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 72c86f28bbc6..ea76ce2c5735 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 000000000000..c67b22f6f8c4 --- /dev/null +++ b/tests/ui/crashes/ice-9445.rs @@ -0,0 +1,3 @@ +const UNINIT: core::mem::MaybeUninit> = core::mem::MaybeUninit::uninit(); + +fn main() {}