Skip to content

Commit c01c494

Browse files
committed
Explain how we encode enums at the encoding site
1 parent f646c1e commit c01c494

File tree

1 file changed

+4
-3
lines changed
  • compiler/rustc_mir/src/const_eval

1 file changed

+4
-3
lines changed

compiler/rustc_mir/src/const_eval/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,11 @@ fn const_to_valtree_inner<'tcx>(
6969
let field = ecx.mplace_field(&place, i).unwrap();
7070
const_to_valtree_inner(ecx, &field)
7171
});
72+
// For enums, we preped their variant index before the variant's fields so we can figure out
73+
// the variant again when just seeing a valtree.
74+
let branches = variant.into_iter().chain(fields);
7275
Some(ty::ValTree::Branch(
73-
ecx.tcx
74-
.arena
75-
.alloc_from_iter(variant.into_iter().chain(fields).collect::<Option<Vec<_>>>()?),
76+
ecx.tcx.arena.alloc_from_iter(branches.collect::<Option<Vec<_>>>()?),
7677
))
7778
};
7879
match place.layout.ty.kind() {

0 commit comments

Comments
 (0)