From c01c49430c8e5a2b5aa7db777f49bd3a18525d0b Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 15 Mar 2021 11:52:26 +0000 Subject: [PATCH] Explain how we encode enums at the encoding site --- compiler/rustc_mir/src/const_eval/mod.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_mir/src/const_eval/mod.rs b/compiler/rustc_mir/src/const_eval/mod.rs index 4086c18c3d2..218b1dadebd 100644 --- a/compiler/rustc_mir/src/const_eval/mod.rs +++ b/compiler/rustc_mir/src/const_eval/mod.rs @@ -69,10 +69,11 @@ fn const_to_valtree_inner<'tcx>( let field = ecx.mplace_field(&place, i).unwrap(); const_to_valtree_inner(ecx, &field) }); + // For enums, we preped their variant index before the variant's fields so we can figure out + // the variant again when just seeing a valtree. + let branches = variant.into_iter().chain(fields); Some(ty::ValTree::Branch( - ecx.tcx - .arena - .alloc_from_iter(variant.into_iter().chain(fields).collect::>>()?), + ecx.tcx.arena.alloc_from_iter(branches.collect::>>()?), )) }; match place.layout.ty.kind() {