diff options
| author | Ralf Jung <post@ralfj.de> | 2024-12-01 13:12:43 +0100 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2024-12-18 11:00:21 +0100 |
| commit | 21de42bf8ddd0f39c766c7705990152302ae1f3b (patch) | |
| tree | fd27ee9da12fb8c8682f7aaddb4dc749cfa1bfe6 /compiler/rustc_transmute/src/layout/tree.rs | |
| parent | 37e74596c0b59e81b9ac58657f92297ef4ccb7ef (diff) | |
| download | rust-21de42bf8ddd0f39c766c7705990152302ae1f3b.tar.gz rust-21de42bf8ddd0f39c766c7705990152302ae1f3b.zip | |
Variants::Single: do not use invalid VariantIdx for uninhabited enums
Diffstat (limited to 'compiler/rustc_transmute/src/layout/tree.rs')
| -rw-r--r-- | compiler/rustc_transmute/src/layout/tree.rs | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/compiler/rustc_transmute/src/layout/tree.rs b/compiler/rustc_transmute/src/layout/tree.rs index 83463babc4f..049f4734e7b 100644 --- a/compiler/rustc_transmute/src/layout/tree.rs +++ b/compiler/rustc_transmute/src/layout/tree.rs @@ -339,14 +339,12 @@ pub(crate) mod rustc { match layout.variants() { Variants::Single { index } => { - // Hilariously, `Single` is used even for 0-variant enums; - // `index` is just junk in that case. - if ty.ty_adt_def().unwrap().variants().is_empty() { - Ok(Self::uninhabited()) - } else { + if let Some(index) = index { // `Variants::Single` on enums with variants denotes that // the enum delegates its layout to the variant at `index`. layout_of_variant(*index, None) + } else { + Ok(Self::uninhabited()) } } Variants::Multiple { tag, tag_encoding, tag_field, .. } => { @@ -504,7 +502,7 @@ pub(crate) mod rustc { ty::Adt(def, args) => { match layout.variants { Variants::Single { index } => { - let field = &def.variant(index).fields[i]; + let field = &def.variant(index.unwrap()).fields[i]; field.ty(cx.tcx(), args) } // Discriminant field for enums (where applicable). |
