rust/compiler/rustc_hir/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
..
hir Rename LifetimeSyntax variants to lang-team-approved names 2025-06-03 09:06:08 -04:00
arena.rs Overhaul UsePath. 2025-06-03 08:23:21 +10:00
def.rs Replace elided_named_lifetimes with mismatched_lifetime_syntaxes 2025-06-04 10:40:04 -04:00
def_path_hash_map.rs Move hashes from rustc_data_structure to rustc_hashes so they can be shared with rust-analyzer 2025-02-16 16:18:30 -05:00
definitions.rs Add DefPathData::OpaqueLifetime to avoid conflicts for remapped opaque lifetimes 2025-05-07 22:17:29 +02:00
diagnostic_items.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
hir.rs Report infer ty errors during hir ty lowering 2025-06-27 07:51:38 +00:00
hir_id.rs impl !PartialOrd for HirId 2025-04-03 09:22:21 +00:00
intravisit.rs collect delayed lints in hir_crate_items 2025-06-13 14:03:01 +02:00
lang_items.rs Auto merge of #141759 - 1c3t3a:discriminants-query, r=saethlin 2025-06-28 10:25:00 +00:00
lib.rs introduce new lint infra 2025-06-12 09:56:47 +02:00
lints.rs introduce new lint infra 2025-06-12 09:56:47 +02:00
pat_util.rs Eliminate PatKind::Path 2025-01-29 15:45:13 +00:00
stable_hash_impls.rs introduce new lint infra 2025-06-12 09:56:47 +02:00
target.rs Implment #[cfg] and #[cfg_attr] in where clauses 2025-03-01 22:02:46 +08:00
tests.rs Allow drivers to supply a list of extra symbols to intern 2025-04-10 13:39:23 +00:00
weak_lang_items.rs Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00