Closed
Description
Summary
Bare array constants currently support primitive scalars, enums, tuples, and nested arrays, but arrays whose element type is a struct are rejected.
This prevents constants such as:
#[repr(C)]
struct Entry {
tag: u8,
value: u32,
}
const TABLE: [Entry; 2] = [
Entry { tag: 1, value: 10 },
Entry { tag: 2, value: 20 },
];from being materialized through the MIR importer when used as bare array values.
Expected behavior
Bare [Struct; N] constants should be materialized using the existing layout-aware aggregate constant decoding path.
The implementation should preserve:
- rustc-recorded struct field offsets,
- padding,
- nested aggregate layout,
- zero-sized and over-aligned struct behavior,
- recursive array/aggregate decoding.
Scope
This issue covers bare array values only.
The following remain out of scope:
- pointer-to-array constants such as
&[Struct; N], - widening immutable-global array promotion to struct elements,
- union constants.
Bare arrays may fall back to element-wise materialization when the element type is not eligible for immutable-global promotion. Pointer-to-array constants do not have that fallback and should retain their existing boundary.
Acceptance criteria
[Struct; N]bare constants are accepted.- Nested struct constants inside arrays are supported.
- Struct padding and field offsets follow rustc layout information.
- Over-aligned zero-sized struct arrays behave correctly.
- Existing pointer-to-array struct rejection remains unchanged.
- Existing array constant behavior does not regress.
- Codegen regression coverage validates the generated LLVM shape for padded and nested struct arrays.
Metadata
Metadata
Assignees
Labels
No labels
Activity