diff options
| author | Ralf Jung <post@ralfj.de> | 2024-12-01 17:33:01 +0100 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2024-12-18 11:01:54 +0100 |
| commit | e023590de407f417e0f3da675a372eca7acf60c6 (patch) | |
| tree | 1250b36437667439bc369777a202d9571cec2f19 /compiler/rustc_transmute | |
| parent | 21de42bf8ddd0f39c766c7705990152302ae1f3b (diff) | |
| download | rust-e023590de407f417e0f3da675a372eca7acf60c6.tar.gz rust-e023590de407f417e0f3da675a372eca7acf60c6.zip | |
make no-variant types a dedicated Variants variant
Diffstat (limited to 'compiler/rustc_transmute')
| -rw-r--r-- | compiler/rustc_transmute/src/layout/tree.rs | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/compiler/rustc_transmute/src/layout/tree.rs b/compiler/rustc_transmute/src/layout/tree.rs index 049f4734e7b..4cc6292a3ee 100644 --- a/compiler/rustc_transmute/src/layout/tree.rs +++ b/compiler/rustc_transmute/src/layout/tree.rs @@ -338,14 +338,11 @@ pub(crate) mod rustc { }; match layout.variants() { + Variants::Empty => Ok(Self::uninhabited()), Variants::Single { index } => { - 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::Single` on enums with variants denotes that + // the enum delegates its layout to the variant at `index`. + layout_of_variant(*index, None) } Variants::Multiple { tag, tag_encoding, tag_field, .. } => { // `Variants::Multiple` denotes an enum with multiple @@ -498,13 +495,15 @@ pub(crate) mod rustc { (ty, layout): (Ty<'tcx>, Layout<'tcx>), i: FieldIdx, ) -> Ty<'tcx> { + // FIXME: Why does this not just use `ty_and_layout_field`? match ty.kind() { ty::Adt(def, args) => { match layout.variants { Variants::Single { index } => { - let field = &def.variant(index.unwrap()).fields[i]; + let field = &def.variant(index).fields[i]; field.ty(cx.tcx(), args) } + Variants::Empty => panic!("there is no field in Variants::Empty types"), // Discriminant field for enums (where applicable). Variants::Multiple { tag, .. } => { assert_eq!(i.as_usize(), 0); |
