https://gcc.gnu.org/g:1b839ec55be7b93beb0118da19c267a0c4d3fcb9
commit r17-3115-g1b839ec55be7b93beb0118da19c267a0c4d3fcb9 Author: Yap Zhi Heng <[email protected]> Date: Tue Jul 21 22:29:09 2026 +0800 gccrs: Small fixes for #[repr(transparent)] gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit(StructStruct)): Update E0690 error message to use the correct variable for number of fields. * typecheck/rust-tyty.cc (ArrayType::is_zero_sized): Catch edge case of array's element type being a ZST with capacity is more than 0. gcc/testsuite/ChangeLog: * rust/compile/repr_transparent_fields.rs: Add more test cases. Signed-off-by: Yap Zhi Heng <[email protected]> Diff: --- gcc/rust/typecheck/rust-hir-type-check-item.cc | 2 +- gcc/rust/typecheck/rust-tyty.cc | 3 +++ gcc/testsuite/rust/compile/repr_transparent_fields.rs | 12 ++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/gcc/rust/typecheck/rust-hir-type-check-item.cc b/gcc/rust/typecheck/rust-hir-type-check-item.cc index 6c1d91132915..44d5434b1269 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-item.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-item.cc @@ -378,7 +378,7 @@ TypeCheckItem::visit (HIR::StructStruct &struct_decl) rust_error_at (struct_decl.get_locus (), ErrorCode::E0690, "transparent struct needs at most one field with " "non-trivial size or alignment, but has %lu", - (unsigned long) struct_decl.get_fields ().size ()); + (unsigned long) num_non_zst); return; } } diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index 825febe6f6ee..bc26692058a2 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -2602,6 +2602,9 @@ ArrayType::is_equal (const BaseType &other) const bool ArrayType::is_zero_sized () const { + if (element_type.get_tyty ()->is_zero_sized ()) + return true; + auto *capacity_ty = get_capacity (); if (capacity_ty != nullptr && capacity_ty->get_kind () == TyTy::TypeKind::CONST) diff --git a/gcc/testsuite/rust/compile/repr_transparent_fields.rs b/gcc/testsuite/rust/compile/repr_transparent_fields.rs index 72219e486741..482460061310 100644 --- a/gcc/testsuite/rust/compile/repr_transparent_fields.rs +++ b/gcc/testsuite/rust/compile/repr_transparent_fields.rs @@ -26,3 +26,15 @@ struct Qux { foo: i32, phantom: PhantomData<i32>, } + +#[repr(transparent)] +struct Quux { + phantom_array: [(); 6], + foo: i32, +} + +#[repr(transparent)] +struct Corge { + empty_array: [i32; 0], + foo: i32, +}
