Skip to content

Commit 7cd34e7

Browse files
Rollup merge of #136985 - zachs18:backend-repr-remove-uninhabited, r=workingjubilee
Do not ignore uninhabited types for function-call ABI purposes. (Remove BackendRepr::Uninhabited) Accepted MCP: rust-lang/compiler-team#832 Fixes #135802 Do not consider the inhabitedness of a type for function call ABI purposes. * Remove the [`rustc_abi::BackendRepr::Uninhabited`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_abi/enum.BackendRepr.html) variant * Instead calculate the `BackendRepr` of uninhabited types "normally" (as though they were not uninhabited "at the top level", but still considering inhabitedness of variants to determine enum layout, etc) * Add an `uninhabited: bool` field to [`rustc_abi::LayoutData`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_abi/struct.LayoutData.html) so inhabitedness of a `LayoutData` can still be queried when necessary (e.g. when determining if an enum variant needs a tag value allocated to it). This should not affect type layouts (size/align/field offset); this should only affect function call ABI, and only of uninhabited types. cc ``@RalfJung``
2 parents e6481ec + 8aba4e6 commit 7cd34e7

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

crates/hir-ty/src/layout.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ fn layout_of_simd_ty(
194194
fields,
195195
backend_repr: BackendRepr::Vector { element: e_abi, count: e_len },
196196
largest_niche: e_ly.largest_niche,
197+
uninhabited: false,
197198
size,
198199
align,
199200
max_repr_align: None,
@@ -297,20 +298,17 @@ pub fn layout_of_ty_query(
297298
.checked_mul(count, dl)
298299
.ok_or(LayoutError::BadCalc(LayoutCalculatorError::SizeOverflow))?;
299300

300-
let backend_repr =
301-
if count != 0 && matches!(element.backend_repr, BackendRepr::Uninhabited) {
302-
BackendRepr::Uninhabited
303-
} else {
304-
BackendRepr::Memory { sized: true }
305-
};
301+
let backend_repr = BackendRepr::Memory { sized: true };
306302

307303
let largest_niche = if count != 0 { element.largest_niche } else { None };
304+
let uninhabited = if count != 0 { element.uninhabited } else { false };
308305

309306
Layout {
310307
variants: Variants::Single { index: struct_variant_idx() },
311308
fields: FieldsShape::Array { stride: element.size, count },
312309
backend_repr,
313310
largest_niche,
311+
uninhabited,
314312
align: element.align,
315313
size,
316314
max_repr_align: None,
@@ -325,6 +323,7 @@ pub fn layout_of_ty_query(
325323
fields: FieldsShape::Array { stride: element.size, count: 0 },
326324
backend_repr: BackendRepr::Memory { sized: false },
327325
largest_niche: None,
326+
uninhabited: false,
328327
align: element.align,
329328
size: Size::ZERO,
330329
max_repr_align: None,
@@ -337,6 +336,7 @@ pub fn layout_of_ty_query(
337336
fields: FieldsShape::Array { stride: Size::from_bytes(1), count: 0 },
338337
backend_repr: BackendRepr::Memory { sized: false },
339338
largest_niche: None,
339+
uninhabited: false,
340340
align: dl.i8_align,
341341
size: Size::ZERO,
342342
max_repr_align: None,

0 commit comments

Comments
 (0)