diff options
| author | Jack Wrenn <jack@wrenn.fyi> | 2024-06-12 22:07:37 +0000 |
|---|---|---|
| committer | Jack Wrenn <jack@wrenn.fyi> | 2024-06-13 01:38:51 +0000 |
| commit | fb662f2126b026c91ddbc17ac3bdb8bd2bf575c5 (patch) | |
| tree | 1293de563facf958e14eaf1676706bd98aba31c8 /compiler/rustc_codegen_llvm/src/errors.rs | |
| parent | 1d43fbbc7348f2bd9260d8532bffa02f5bd2c9ac (diff) | |
| download | rust-fb662f2126b026c91ddbc17ac3bdb8bd2bf575c5.tar.gz rust-fb662f2126b026c91ddbc17ac3bdb8bd2bf575c5.zip | |
safe transmute: support `Variants::Single` enums
Previously, the implementation of `Tree::from_enum` incorrectly treated enums with `Variants::Single` and `Variants::Multiple` identically. This is incorrect for `Variants::Single` enums, which delegate their layout to that of a variant with a particular index (or no variant at all if the enum is empty). This flaw manifested first as an ICE. `Tree::from_enum` attempted to compute the tag of variants other than the one at `Variants::Single`'s `index`, and fell afoul of a sanity-checking assertion in `compiler/rustc_const_eval/src/interpret/discriminant.rs`. This assertion is non-load-bearing, and can be removed; the routine its in is well-behaved even without it. With the assertion removed, the proximate issue becomes apparent: calling `Tree::from_variant` on a variant that does not exist is ill-defined. A sanity check the given variant has `FieldShapes::Arbitrary` fails, and the analysis is (correctly) aborted with `Err::NotYetSupported`. This commit corrects this chain of failures by ensuring that `Tree::from_variant` is not called on variants that are, as far as layout is concerned, nonexistent. Specifically, the implementation of `Tree::from_enum` is now partitioned into three cases: 1. enums that are uninhabited 2. enums for which all but one variant is uninhabited 3. enums with multiple inhabited variants `Tree::from_variant` is now only invoked in the third case. In the first case, `Tree::uninhabited()` is produced. In the second case, the layout is delegated to `Variants::Single`'s index. Fixes #125811
Diffstat (limited to 'compiler/rustc_codegen_llvm/src/errors.rs')
0 files changed, 0 insertions, 0 deletions
