From: Yap Zhi Heng <[email protected]>

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]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.


Commit on github: 
https://github.com/Rust-GCC/gccrs/commit/a29a82e68375cb41cce994c66ae62fa3848cb500

The commit has NOT been mentioned in any issue.

The commit has been mentioned in the following pull-request(s):
 - https://github.com/Rust-GCC/gccrs/pull/4716

 gcc/rust/typecheck/rust-hir-type-check-item.cc       |  2 +-
 gcc/rust/typecheck/rust-tyty.cc                      |  3 +++
 .../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 6c1d91132..44d5434b1 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 825febe6f..bc2669205 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 72219e486..482460061 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,
+}

base-commit: 50503646c2250068777039f8618de705ce2dbd38
-- 
2.54.0

Reply via email to