From 5af79242ac1b04f3ab79548f782dacac331a2f67 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 27 Jun 2025 17:02:47 +0200 Subject: [PATCH] tag_for_variant: properly pass TypingEnv --- compiler/rustc_const_eval/src/const_eval/mod.rs | 13 ++++--------- compiler/rustc_middle/src/query/mod.rs | 2 +- compiler/rustc_transmute/src/layout/tree.rs | 4 +++- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_const_eval/src/const_eval/mod.rs b/compiler/rustc_const_eval/src/const_eval/mod.rs index 73cb1e774361d..9e65161f64ab6 100644 --- a/compiler/rustc_const_eval/src/const_eval/mod.rs +++ b/compiler/rustc_const_eval/src/const_eval/mod.rs @@ -67,18 +67,13 @@ pub(crate) fn try_destructure_mir_constant_for_user_output<'tcx>( #[instrument(skip(tcx), level = "debug")] pub fn tag_for_variant_provider<'tcx>( tcx: TyCtxt<'tcx>, - (ty, variant_index): (Ty<'tcx>, VariantIdx), + key: ty::PseudoCanonicalInput<'tcx, (Ty<'tcx>, VariantIdx)>, ) -> Option { + let (ty, variant_index) = key.value; assert!(ty.is_enum()); - // FIXME: This uses an empty `TypingEnv` even though - // it may be used by a generic CTFE. - let ecx = InterpCx::new( - tcx, - ty.default_span(tcx), - ty::TypingEnv::fully_monomorphized(), - crate::const_eval::DummyMachine, - ); + let ecx = + InterpCx::new(tcx, ty.default_span(tcx), key.typing_env, crate::const_eval::DummyMachine); let layout = ecx.layout_of(ty).unwrap(); ecx.tag_for_variant(layout, variant_index).unwrap().map(|(tag, _tag_field)| tag) diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 3668f4e12f5d9..0f0afc80f3e5d 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -1311,7 +1311,7 @@ rustc_queries! { /// /// This query will panic for uninhabited variants and if the passed type is not an enum. query tag_for_variant( - key: (Ty<'tcx>, abi::VariantIdx) + key: PseudoCanonicalInput<'tcx, (Ty<'tcx>, abi::VariantIdx)>, ) -> Option { desc { "computing variant tag for enum" } } diff --git a/compiler/rustc_transmute/src/layout/tree.rs b/compiler/rustc_transmute/src/layout/tree.rs index 372b4f5353abb..150f5d118e09b 100644 --- a/compiler/rustc_transmute/src/layout/tree.rs +++ b/compiler/rustc_transmute/src/layout/tree.rs @@ -432,7 +432,9 @@ pub(crate) mod rustc { if variant_layout.is_uninhabited() { return Ok(Self::uninhabited()); } - let tag = cx.tcx().tag_for_variant((cx.tcx().erase_regions(ty), index)); + let tag = cx.tcx().tag_for_variant( + cx.typing_env.as_query_input((cx.tcx().erase_regions(ty), index)), + ); let variant_def = Def::Variant(def.variant(index)); Self::from_variant( variant_def,