rust/compiler/rustc_const_eval/src
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
..
check_consts Rollup merge of #143092 - RalfJung:const-check-lifetime-ext, r=oli-obk 2025-06-27 22:13:06 +02:00
const_eval Auto merge of #141759 - 1c3t3a:discriminants-query, r=saethlin 2025-06-28 10:25:00 +00:00
interpret Rollup merge of #143046 - RalfJung:zst-unsafe-cell, r=lcnr,oli-obk 2025-06-27 22:13:05 +02:00
util Add InterpCx::layout_of with tracing, shadowing LayoutOf 2025-06-27 11:49:22 +02:00
errors.rs const checks: avoid 'top-level scope' terminology 2025-06-27 17:03:48 +02:00
lib.rs update cfg(bootstrap) 2025-05-12 15:33:37 +02:00