diff options
| author | Oli Scherer <github35764891676564198441@oli-obk.de> | 2021-03-15 11:52:26 +0000 |
|---|---|---|
| committer | Oli Scherer <github35764891676564198441@oli-obk.de> | 2021-03-15 12:06:52 +0000 |
| commit | c01c49430c8e5a2b5aa7db777f49bd3a18525d0b (patch) | |
| tree | 808ba744523894804d9f20ce41b3f74c3c52b987 | |
| parent | f646c1e43445f5edff741c8572cb7d52bdb97ce1 (diff) | |
| download | rust-c01c49430c8e5a2b5aa7db777f49bd3a18525d0b.tar.gz rust-c01c49430c8e5a2b5aa7db777f49bd3a18525d0b.zip | |
Explain how we encode enums at the encoding site
| -rw-r--r-- | compiler/rustc_mir/src/const_eval/mod.rs | 7 |
1 files 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::<Option<Vec<_>>>()?), + ecx.tcx.arena.alloc_from_iter(branches.collect::<Option<Vec<_>>>()?), )) }; match place.layout.ty.kind() { |
