Skip to content

Commit 5af7924

Browse files
committed
tag_for_variant: properly pass TypingEnv
1 parent e61dd43 commit 5af7924

File tree

3 files changed

+8
-11
lines changed
  • compiler
    • rustc_const_eval/src/const_eval
    • rustc_middle/src/query
    • rustc_transmute/src/layout

3 files changed

+8
-11
lines changed

compiler/rustc_const_eval/src/const_eval/mod.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,13 @@ pub(crate) fn try_destructure_mir_constant_for_user_output<'tcx>(
6767
#[instrument(skip(tcx), level = "debug")]
6868
pub fn tag_for_variant_provider<'tcx>(
6969
tcx: TyCtxt<'tcx>,
70-
(ty, variant_index): (Ty<'tcx>, VariantIdx),
70+
key: ty::PseudoCanonicalInput<'tcx, (Ty<'tcx>, VariantIdx)>,
7171
) -> Option<ty::ScalarInt> {
72+
let (ty, variant_index) = key.value;
7273
assert!(ty.is_enum());
7374

74-
// FIXME: This uses an empty `TypingEnv` even though
75-
// it may be used by a generic CTFE.
76-
let ecx = InterpCx::new(
77-
tcx,
78-
ty.default_span(tcx),
79-
ty::TypingEnv::fully_monomorphized(),
80-
crate::const_eval::DummyMachine,
81-
);
75+
let ecx =
76+
InterpCx::new(tcx, ty.default_span(tcx), key.typing_env, crate::const_eval::DummyMachine);
8277

8378
let layout = ecx.layout_of(ty).unwrap();
8479
ecx.tag_for_variant(layout, variant_index).unwrap().map(|(tag, _tag_field)| tag)

compiler/rustc_middle/src/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1311,7 +1311,7 @@ rustc_queries! {
13111311
///
13121312
/// This query will panic for uninhabited variants and if the passed type is not an enum.
13131313
query tag_for_variant(
1314-
key: (Ty<'tcx>, abi::VariantIdx)
1314+
key: PseudoCanonicalInput<'tcx, (Ty<'tcx>, abi::VariantIdx)>,
13151315
) -> Option<ty::ScalarInt> {
13161316
desc { "computing variant tag for enum" }
13171317
}

compiler/rustc_transmute/src/layout/tree.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,9 @@ pub(crate) mod rustc {
432432
if variant_layout.is_uninhabited() {
433433
return Ok(Self::uninhabited());
434434
}
435-
let tag = cx.tcx().tag_for_variant((cx.tcx().erase_regions(ty), index));
435+
let tag = cx.tcx().tag_for_variant(
436+
cx.typing_env.as_query_input((cx.tcx().erase_regions(ty), index)),
437+
);
436438
let variant_def = Def::Variant(def.variant(index));
437439
Self::from_variant(
438440
variant_def,

0 commit comments

Comments
 (0)