diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-12-03 21:55:26 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-03 21:55:26 +0100 |
| commit | 6e87eb58ede97cce4bd1e392694f88a2a2936e84 (patch) | |
| tree | 72bbeced46643de172e2ebc4ed2b7968921173dc /compiler/rustc_const_eval/src/const_eval | |
| parent | 58fac8fe72c0cdbcf6622a03bf0706dba21bba7a (diff) | |
| parent | 611a99188e86bdff0cb7c2e1806eff77fedc54b1 (diff) | |
| download | rust-6e87eb58ede97cce4bd1e392694f88a2a2936e84.tar.gz rust-6e87eb58ede97cce4bd1e392694f88a2a2936e84.zip | |
Rollup merge of #133681 - RalfJung:niches, r=wesleywiser
improve TagEncoding::Niche docs, sanity check, and UB checks Turns out the `niche_variants` range can actually contain the `untagged_variant`. We should report this as UB in Miri, so this PR implements that. Also rename `partially_check_layout` to `layout_sanity_check` for better consistency with how similar functions are called in other parts of the compiler. Turns out my adjustments to the transmutation logic also fix https://github.com/rust-lang/rust/issues/126267.
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) } |
