Change:
<!-- Thank you for finding an Internal Compiler Error! If possible, try to provide a minimal verifiable example. You can read "Rust Bug Minimization Patterns" for how to create smaller examples. --(reduced) <details<summary<strongOriginal Code</strong</summary<p</p</details- Above original code is mutated from I guess at the top causes ICE <!-- If you're using the stable version of the compiler, you should also check if the bug also exists in the beta or nightly versions. --: <!-- Include a backtrace in the code block by setting in your environment. E.g. . --<details<summary<strongBacktrace</strong</summary<p</p</details- ICE occurred at
label regression-from-stable-to-beta
searched nightlies: from nightly-2024-02-01 to nightly-2024-04-10 regressed nightly: nightly-2024-02-09 searched commit range: regressed commit: <details<summarybisected with <a href=''cargo-bisect-rustc</av0.6.7</summaryHost triple: aarch64-unknown-linux-gnu Reproduce with: </detailscc
WG-prioritization assigning priority (). label -I-prioritize +P-medium

Discussion:
}; for (local, val) in cpv.can_const_prop.iter_enumerated_mut() { let ty = body.local_decls[local].ty; <del> match tcx.layout_of(param_env.and(ty)) { Ok(layout) if layout.size < Size::from_bytes(MAX_ALLOC_LIMIT) => {} // Either the layout fails to compute, then we can't use this local anyway // or the local is too large, then we don't want to. _ => { *val = ConstPropMode::NoPropagation; continue; </del> <ins> if ty.is_union() { // Do not const prop unions as they can // ICE during layout calc *val = ConstPropMode::NoPropagation; } else { match tcx.layout_of(param_env.and(ty)) { Ok(layout) if layout.size < Size::from_bytes(MAX_ALLOC_LIMIT) => {} // Either the layout fails to compute, then we can't use this local anyway // or the local is too large, then we don't want to. _ => { *val = ConstPropMode::NoPropagation; continue; } </ins> } } }

<del> //@ known-bug: #123710 #[repr(packed)] #[repr(u32)] enum E { A, B, C, } fn main() { union InvalidTag { int: u32, e: E, } let _invalid_tag = InvalidTag { int: 4 }; } </del>

<ins> // Regression test for issue 123710. // Tests that the we do not ICE in KnownPanicsLint // when a union contains an enum with an repr(packed), // which is a repr not supported for enums #[repr(packed)] //~^ ERROR attribute should be applied to a struct or union #[repr(u32)] enum E { A, B, C, } fn main() { union InvalidTag { int: u32, e: E, //~^ ERROR field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union } let _invalid_tag = InvalidTag { int: 4 }; } </ins>

<ins> error[E0517]: attribute should be applied to a struct or union --> $DIR/ice-const-prop-unions-known-panics-lint-123710.rs:6:8 | LL |   #[repr(packed)] |          ^^^^^^ ... LL | / enum E { LL | |     A, LL | |     B, LL | |     C, LL | | } | |_- not a struct or union error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union --> $DIR/ice-const-prop-unions-known-panics-lint-123710.rs:18:9 | LL |         e: E, |         ^^^^ | = note: union fields must not have drop side-effects, which is currently enforced via either `Copy` or `ManuallyDrop<...>` help: wrap the field type in `ManuallyDrop<...>` | LL |         e: std::mem::ManuallyDrop<E>, |            +++++++++++++++++++++++ + error: aborting due to 2 previous errors Some errors have detailed explanations: E0517, E0740. For more information about an error, try `rustc --explain E0517`. </ins>