From: Zhi Heng <yapz...@gmail.com>

gcc/rust/ChangeLog:

        * typecheck/rust-hir-type-check-base.cc: Set enum representing
        type properly if repr is an integer type.
        * typecheck/rust-hir-type-check-item.cc: Update comments.

Signed-off-by: Yap Zhi Heng <yapz...@gmail.com>
---
 gcc/rust/typecheck/rust-hir-type-check-base.cc | 13 ++++++++++---
 gcc/rust/typecheck/rust-hir-type-check-item.cc |  2 +-
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.cc 
b/gcc/rust/typecheck/rust-hir-type-check-base.cc
index c6bb147c1c8..2ee0d0833e8 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-base.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-base.cc
@@ -308,7 +308,7 @@ TypeCheckBase::parse_repr_options (const AST::AttrVec 
&attrs, location_t locus)
   repr.pack = 0;
   repr.align = 0;
 
-  // FIXME handle repr types....
+  // FIXME handle non-integer repr types....
   bool ok = context->lookup_builtin ("isize", &repr.repr);
   rust_assert (ok);
 
@@ -353,8 +353,10 @@ TypeCheckBase::parse_repr_options (const AST::AttrVec 
&attrs, location_t locus)
          // manually parsing the string "packed(2)" here.
 
          size_t oparen = inline_option.find ('(', 0);
-         bool is_pack = false, is_align = false, is_c = false,
-              is_integer = false;
+         bool is_pack = false;
+         bool is_align = false;
+         bool is_c = false;
+         bool is_integer = false;
          unsigned char value = 1;
 
          if (oparen == std::string::npos)
@@ -409,6 +411,11 @@ TypeCheckBase::parse_repr_options (const AST::AttrVec 
&attrs, location_t locus)
          else if (is_integer)
            {
              repr.repr_kind = TyTy::ADTType::ReprKind::INT;
+             bool ok = context->lookup_builtin (inline_option, &repr.repr);
+             if (!ok)
+               {
+                 rust_error_at (attr.get_locus (), "Invalid repr type");
+               }
            }
 
          delete meta_items;
diff --git a/gcc/rust/typecheck/rust-hir-type-check-item.cc 
b/gcc/rust/typecheck/rust-hir-type-check-item.cc
index 85a9ada2b9b..177dd556293 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-item.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-item.cc
@@ -355,7 +355,7 @@ TypeCheckItem::visit (HIR::Enum &enum_decl)
       variants.push_back (field_type);
     }
 
-  // Check for zero-variant enum compatibility before processing repr attribute
+  // Check for zero-variant enum compatibility
   if (enum_decl.is_zero_variant ())
     {
       if (repr.repr_kind == TyTy::ADTType::ReprKind::INT
-- 
2.49.0

Reply via email to