Skip to content

Commit 994ed31

Browse files
authored
Rollup merge of #143096 - RalfJung:tag_for_variant, r=compiler-errors
tag_for_variant: properly pass TypingEnv Hard-coding `fully_monomorphized` here does not seem right... This came up [on Zulip](https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/.E2.9C.94.20VariantId.3DDiscriminant.20when.20tag.20is.20niche.20encoded.3F/with/526103956).
2 parents 088f6ab + 5af7924 commit 994ed31

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
@@ -66,18 +66,13 @@ pub(crate) fn try_destructure_mir_constant_for_user_output<'tcx>(
6666
#[instrument(skip(tcx), level = "debug")]
6767
pub fn tag_for_variant_provider<'tcx>(
6868
tcx: TyCtxt<'tcx>,
69-
(ty, variant_index): (Ty<'tcx>, VariantIdx),
69+
key: ty::PseudoCanonicalInput<'tcx, (Ty<'tcx>, VariantIdx)>,
7070
) -> Option<ty::ScalarInt> {
71+
let (ty, variant_index) = key.value;
7172
assert!(ty.is_enum());
7273

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

8277
let layout = ecx.layout_of(ty).unwrap();
8378
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)