diff options
| author | Goldstein <root@goldstein.rs> | 2024-03-25 20:44:58 +0300 |
|---|---|---|
| committer | Goldstein <root@goldstein.rs> | 2024-06-28 20:19:45 +0300 |
| commit | 71dfbeabc4abe992a42025a5b7341e1ceec22e0b (patch) | |
| tree | 352b7a8b9aaf8ea6ceb2b9e228059421fdb238a1 /compiler | |
| parent | 1a851da73cdeb02e2c62d301aa6bd98e515a50da (diff) | |
| download | rust-71dfbeabc4abe992a42025a5b7341e1ceec22e0b.tar.gz rust-71dfbeabc4abe992a42025a5b7341e1ceec22e0b.zip | |
Disable dead variant removal for `#[repr(C)]` enums.
See https://github.com/rust-lang/unsafe-code-guidelines/issues/500.
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_abi/src/layout.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_abi/src/lib.rs | 2 |
2 files changed, 3 insertions, 3 deletions
diff --git a/compiler/rustc_abi/src/layout.rs b/compiler/rustc_abi/src/layout.rs index a95ef4c460f..aff0d70bf90 100644 --- a/compiler/rustc_abi/src/layout.rs +++ b/compiler/rustc_abi/src/layout.rs @@ -186,7 +186,7 @@ pub trait LayoutCalculator { let (present_first, present_second) = { let mut present_variants = variants .iter_enumerated() - .filter_map(|(i, v)| if absent(v) { None } else { Some(i) }); + .filter_map(|(i, v)| if !repr.c() && absent(v) { None } else { Some(i) }); (present_variants.next(), present_variants.next()) }; let present_first = match present_first { @@ -621,7 +621,7 @@ where let discr_type = repr.discr_type(); let bits = Integer::from_attr(dl, discr_type).size().bits(); for (i, mut val) in discriminants { - if variants[i].iter().any(|f| f.abi.is_uninhabited()) { + if !repr.c() && variants[i].iter().any(|f| f.abi.is_uninhabited()) { continue; } if discr_type.is_signed() { diff --git a/compiler/rustc_abi/src/lib.rs b/compiler/rustc_abi/src/lib.rs index 5e3f64540e4..1e5e391d19b 100644 --- a/compiler/rustc_abi/src/lib.rs +++ b/compiler/rustc_abi/src/lib.rs @@ -1401,7 +1401,7 @@ pub enum Variants<FieldIdx: Idx, VariantIdx: Idx> { /// Single enum variants, structs/tuples, unions, and all non-ADTs. Single { index: VariantIdx }, - /// Enum-likes with more than one inhabited variant: each variant comes with + /// Enum-likes with more than one variant: each variant comes with /// a *discriminant* (usually the same as the variant index but the user can /// assign explicit discriminant values). That discriminant is encoded /// as a *tag* on the machine. The layout of each variant is |
