diff options
| author | Ralf Jung <post@ralfj.de> | 2024-11-30 18:06:33 +0100 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2024-11-30 18:26:30 +0100 |
| commit | a36652c274e25802230e5188bceab8a92a3e7346 (patch) | |
| tree | 14f439cc9310a167692e8c04bccc28fe636aee04 /compiler/rustc_const_eval/src/const_eval | |
| parent | ce95a44db65f7f595812a52df6b2f0bc479bd290 (diff) | |
report UB when the niche value refers to the untagged variant
Diffstat (limited to 'compiler/rustc_const_eval/src/const_eval')
| -rw-r--r-- | compiler/rustc_const_eval/src/const_eval/mod.rs | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/compiler/rustc_const_eval/src/const_eval/mod.rs b/compiler/rustc_const_eval/src/const_eval/mod.rs index 8cbdcd68e13..34f795bda75 100644 --- a/compiler/rustc_const_eval/src/const_eval/mod.rs +++ b/compiler/rustc_const_eval/src/const_eval/mod.rs @@ -2,6 +2,7 @@ use rustc_abi::VariantIdx; use rustc_middle::query::{Key, TyCtxtAt}; +use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::{bug, mir}; use tracing::instrument; @@ -85,5 +86,6 @@ pub fn tag_for_variant_provider<'tcx>( crate::const_eval::DummyMachine, ); - ecx.tag_for_variant(ty, variant_index).unwrap().map(|(tag, _tag_field)| tag) + let layout = ecx.layout_of(ty).unwrap(); + ecx.tag_for_variant(layout, variant_index).unwrap().map(|(tag, _tag_field)| tag) } |
