rust/compiler/rustc_smir/src/stable_mir
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
..
mir Insert checks for enum discriminants when debug assertions are enabled 2025-06-27 09:37:36 +00:00
abi.rs add extern "custom" functions 2025-06-12 20:27:10 +02:00
compiler_interface.rs Add discriminant_for_variant to CoroutineDef 2025-06-16 10:51:57 +03:00
crate_def.rs let rustc_smir host stable_mir for refactoring 2025-04-05 18:23:07 +08:00
error.rs let rustc_smir host stable_mir for refactoring 2025-04-05 18:23:07 +08:00
mir.rs let rustc_smir host stable_mir for refactoring 2025-04-05 18:23:07 +08:00
mod.rs let rustc_smir host stable_mir for refactoring 2025-04-05 18:23:07 +08:00
target.rs let rustc_smir host stable_mir for refactoring 2025-04-05 18:23:07 +08:00
ty.rs Rollup merge of #142884 - makai410:coroutine-body, r=celinval 2025-06-26 15:47:21 +02:00
visitor.rs let rustc_smir host stable_mir for refactoring 2025-04-05 18:23:07 +08:00