rust/compiler/rustc_const_eval/src/const_eval
bors b63223c152 Auto merge of #141759 - 1c3t3a:discriminants-query, r=saethlin
Insert checks for enum discriminants when debug assertions are enabled

Similar to the existing null-pointer and alignment checks, this checks for valid enum discriminants on creation of enums through unsafe transmutes. Essentially this sanitizes patterns like the following:
```rust
let val: MyEnum = unsafe { std::mem::transmute<u32, MyEnum>(42) };
```

An extension of this check will be done in a follow-up that explicitly sanitizes for extern enum values that come into Rust from e.g. C/C++.

This check is similar to Miri's capabilities of checking for valid construction of enum values.

This PR is inspired by saethlin@'s PR
https://github.com/rust-lang/rust/pull/104862. Thank you so much for keeping this code up and the detailed comments!

I also pair-programmed large parts of this together with vabr-g@.

r? `@saethlin`
2025-06-28 10:25:00 +00:00
..
dummy_machine.rs Rollup merge of #141513 - nia-e:allocbytes-extend, r=RalfJung 2025-05-27 01:29:20 +08:00
error.rs Use the informative error as the main const eval error message 2025-06-02 15:37:15 +00:00
eval_queries.rs Add InterpCx::layout_of with tracing, shadowing LayoutOf 2025-06-27 11:49:22 +02:00
fn_queries.rs Methods of const traits are const 2025-01-15 15:57:06 +00:00
machine.rs Auto merge of #141759 - 1c3t3a:discriminants-query, r=saethlin 2025-06-28 10:25:00 +00:00
mod.rs Rollup merge of #143096 - RalfJung:tag_for_variant, r=compiler-errors 2025-06-27 22:13:06 +02:00
valtrees.rs Add InterpCx::layout_of with tracing, shadowing LayoutOf 2025-06-27 11:49:22 +02:00