rust/compiler
Jubilee d33ec8ed8c
Rollup merge of #126358 - jswrenn:fix-125811, r=compiler-errors
safe transmute: support `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
2024-06-12 20:03:22 -07:00
..
rustc Change SIGPIPE ui from #[unix_sigpipe = "..."] to -Zon-broken-pipe=... 2024-05-02 19:48:29 +02:00
rustc_abi Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_arena Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_ast Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_ast_ir Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_ast_lowering Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_ast_passes Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_ast_pretty Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_attr Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_baked_icu_data Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_borrowck Auto merge of #125069 - amandasystems:scc-refactor, r=nikomatsakis 2024-06-12 23:15:33 +00:00
rustc_builtin_macros Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_codegen_cranelift Auto merge of #126319 - workingjubilee:rollup-lendnud, r=workingjubilee 2024-06-12 11:10:50 +00:00
rustc_codegen_gcc ScalarInt: size mismatches are a bug, do not delay the panic 2024-06-10 13:43:16 +02:00
rustc_codegen_llvm Rollup merge of #126324 - zmodem:loongarch, r=nikic 2024-06-12 14:26:28 -04:00
rustc_codegen_ssa Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_const_eval Rollup merge of #126358 - jswrenn:fix-125811, r=compiler-errors 2024-06-12 20:03:22 -07:00
rustc_data_structures Address code review comments on the comments 2024-06-12 15:48:34 +02:00
rustc_driver Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_driver_impl Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_error_codes Auto merge of #126319 - workingjubilee:rollup-lendnud, r=workingjubilee 2024-06-12 11:10:50 +00:00
rustc_error_messages Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_errors Auto merge of #125410 - fmease:adj-lint-diag-api, r=nnethercote 2024-05-27 08:44:12 +00:00
rustc_expand Rollup merge of #125913 - fmease:early-lints-spruce-up-some-diags, r=Nadrieril 2024-06-11 09:14:34 +01:00
rustc_feature Auto merge of #126273 - pietroalbini:pa-bootstrap-update, r=Mark-Simulacrum 2024-06-12 18:15:32 +00:00
rustc_fluent_macro Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_fs_util Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_graphviz Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_hir Rollup merge of #126303 - sancho20021:patch-1, r=compiler-errors 2024-06-12 20:03:20 -07:00
rustc_hir_analysis Rollup merge of #126340 - fee1-dead-contrib:fix-predicates_of-comments, r=compiler-errors 2024-06-12 14:26:29 -04:00
rustc_hir_pretty Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_hir_typeck Rollup merge of #126328 - RalfJung:is_none_or, r=workingjubilee 2024-06-12 20:03:20 -07:00
rustc_incremental Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_index Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_index_macros Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_infer Rollup merge of #126353 - compiler-errors:move-match, r=lcnr 2024-06-12 20:03:21 -07:00
rustc_interface Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_lexer Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_lint Auto merge of #126273 - pietroalbini:pa-bootstrap-update, r=Mark-Simulacrum 2024-06-12 18:15:32 +00:00
rustc_lint_defs Rollup merge of #126356 - epage:check-cfg, r=Urgau 2024-06-12 20:03:22 -07:00
rustc_llvm Auto merge of #125141 - SergioGasquez:feat/no_std-xtensa, r=davidtwco 2024-06-12 13:43:31 +00:00
rustc_log Bump tracing-tree and allow rendering lines again 2024-06-12 10:11:41 +00:00
rustc_macros Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_metadata Only compute specializes query if specialization is enabled in the crate of the specialized impl 2024-06-07 15:58:50 -04:00
rustc_middle Stop passing traitref/traitpredicate by ref 2024-06-12 20:57:24 -04:00
rustc_mir_build Add TODO comment to unsafe env modification 2024-06-12 17:51:18 +02:00
rustc_mir_dataflow Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_mir_transform Rollup merge of #126294 - Zalathar:spans-refiner, r=oli-obk 2024-06-12 15:45:00 +02:00
rustc_monomorphize Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_next_trait_solver Remove some unused crate dependencies. 2024-06-10 19:55:49 +10:00
rustc_parse Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_parse_format Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_passes Rollup merge of #126276 - mu001999-contrib:dead/enhance, r=fee1-dead 2024-06-12 14:26:26 -04:00
rustc_pattern_analysis Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_privacy Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_query_impl Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_query_system Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_resolve Rollup merge of #126234 - Bryanskiy:delegation-no-entry-ice, r=petrochenkov 2024-06-11 09:14:35 +01:00
rustc_sanitizers Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_serialize Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_session Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_smir Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_span rustc_span: Optimize syntax context updates in spans 2024-06-10 02:20:16 +03:00
rustc_symbol_mangling Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_target Rollup merge of #126324 - zmodem:loongarch, r=nikic 2024-06-12 14:26:28 -04:00
rustc_trait_selection Rollup merge of #126353 - compiler-errors:move-match, r=lcnr 2024-06-12 20:03:21 -07:00
rustc_traits Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_transmute safe transmute: support Variants::Single enums 2024-06-13 01:38:51 +00:00
rustc_ty_utils Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_type_ir Rollup merge of #126075 - compiler-errors:remove-debugwithinfcx, r=lcnr 2024-06-12 15:44:58 +02:00
rustc_type_ir_macros Uplift TraitPredicate 2024-05-11 18:20:00 -04:00
stable_mir Remove some unused crate dependencies. 2024-06-10 19:55:49 +10:00