From a6d6601b20e53322e9b69ad2bd1aad8154250134 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 3 May 2026 13:52:01 +0200 Subject: [PATCH] interpret: correctly deal with repr(transparent) enums --- compiler/rustc_const_eval/src/interpret/call.rs | 2 +- src/tools/miri/tests/pass/function_calls/abi_compat.rs | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_const_eval/src/interpret/call.rs b/compiler/rustc_const_eval/src/interpret/call.rs index 5ec0344592da5..edbb668024455 100644 --- a/compiler/rustc_const_eval/src/interpret/call.rs +++ b/compiler/rustc_const_eval/src/interpret/call.rs @@ -81,7 +81,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { ) -> TyAndLayout<'tcx> { match layout.ty.kind() { ty::Adt(adt_def, _) if adt_def.repr().transparent() && may_unfold(*adt_def) => { - assert!(!adt_def.is_enum()); + assert_matches!(layout.variants, rustc_abi::Variants::Single { .. }); // Find the non-1-ZST field, and recurse. let (_, field) = layout.non_1zst_field(self).unwrap(); self.unfold_transparent(field, may_unfold) diff --git a/src/tools/miri/tests/pass/function_calls/abi_compat.rs b/src/tools/miri/tests/pass/function_calls/abi_compat.rs index cd48bd2accb27..ca76897faea86 100644 --- a/src/tools/miri/tests/pass/function_calls/abi_compat.rs +++ b/src/tools/miri/tests/pass/function_calls/abi_compat.rs @@ -63,13 +63,20 @@ fn test_abi_newtype() { #[repr(transparent)] #[derive(Copy, Clone)] struct Wrapper3(Zst, T, [u8; 0]); + #[repr(transparent)] + #[derive(Copy, Clone)] + enum Wrapper4 { + V(Zst, T, [u8; 0]) + } let t = T::default(); test_abi_compat(t, Wrapper(t)); test_abi_compat(t, Wrapper2(t, ())); test_abi_compat(t, Wrapper2a((), t)); test_abi_compat(t, Wrapper3(Zst, t, [])); - test_abi_compat(t, mem::MaybeUninit::new(t)); // MaybeUninit is `repr(transparent)` + test_abi_compat(t, Wrapper4::V(Zst, t, [])); + // MaybeUninit is `repr(transparent)`; that covers the `union` case. + test_abi_compat(t, mem::MaybeUninit::new(t)); } fn main() {