diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2025-03-13 00:39:18 -0700 |
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2025-03-13 00:39:18 -0700 |
| commit | 2b15dd1dddf3e412dd4a1fee1ab342cb719eaef1 (patch) | |
| tree | 15fab1672cf92ed0e775c55a5ec2232057c65373 | |
| parent | 143f39362aa3fe30e19de5d2a29bf6535e8f975f (diff) | |
| download | rust-2b15dd1dddf3e412dd4a1fee1ab342cb719eaef1.tar.gz rust-2b15dd1dddf3e412dd4a1fee1ab342cb719eaef1.zip | |
Add more comments to discriminant calculations.
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/mir/operand.rs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/compiler/rustc_codegen_ssa/src/mir/operand.rs b/compiler/rustc_codegen_ssa/src/mir/operand.rs index cfebc8840fa..7e355b6406a 100644 --- a/compiler/rustc_codegen_ssa/src/mir/operand.rs +++ b/compiler/rustc_codegen_ssa/src/mir/operand.rs @@ -428,9 +428,14 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> { let dl = &bx.tcx().data_layout; let cast_to_layout = bx.cx().layout_of(cast_to); let cast_to = bx.cx().immediate_backend_type(cast_to_layout); + + // We check uninhabitedness separately because a type like + // `enum Foo { Bar(i32, !) }` is still reported as `Variants::Single`, + // *not* as `Variants::Empty`. if self.layout.is_uninhabited() { return bx.cx().const_poison(cast_to); } + let (tag_scalar, tag_encoding, tag_field) = match self.layout.variants { Variants::Empty => unreachable!("we already handled uninhabited types"), Variants::Single { index } => { @@ -438,7 +443,11 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> { if let Some(discr) = self.layout.ty.discriminant_for_variant(bx.tcx(), index) { discr.val } else { + // This arm is for types which are neither enums nor coroutines, + // and thus for which the only possible "variant" should be the first one. assert_eq!(index, FIRST_VARIANT); + // There's thus no actual discriminant to return, so we return + // what it would have been if this was a single-variant enum. 0 }; return bx.cx().const_uint_big(cast_to, discr_val); |
