[gcc r17-3104] gccrs: rust: Add const getter overloads for HIR pattern fields

Arthur Cohen via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:6614915cf4cca6d875a018587096af4519b548ac

commit r17-3104-g6614915cf4cca6d875a018587096af4519b548ac
Author: Egas Ribeiro <[email protected]>
Date:   Tue May 19 17:52:48 2026 +0100

    gccrs: rust: Add const getter overloads for HIR pattern fields
    
    These const overloads are needed by the type-aware refutability check in
    HIR pattern nodes, which accesses pattern fields through const
    references.
    
            Addresses: Rust-GCC#2082
    
    gcc/rust/ChangeLog:
    
            * hir/tree/rust-hir-pattern.h: Add const overloads.
    
    Co-authored-by: João Novo <[email protected]>
    Signed-off-by: Egas Ribeiro <[email protected]>

Diff:
---
 gcc/rust/hir/tree/rust-hir-pattern.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/gcc/rust/hir/tree/rust-hir-pattern.h b/gcc/rust/hir/tree/rust-hir-pattern.h
index c5997c11d6f9..bc9c63fae0a1 100644
--- a/gcc/rust/hir/tree/rust-hir-pattern.h
+++ b/gcc/rust/hir/tree/rust-hir-pattern.h
@@ -586,8 +586,13 @@ public:
   void accept_vis (HIRFullVisitor &vis) override;
 
   TupleIndex get_index () { return index; }
+
+  TupleIndex get_index () const { return index; }
+
   Pattern &get_tuple_pattern () { return *tuple_pattern; }
 
+  const Pattern &get_tuple_pattern () const { return *tuple_pattern; }
+
   ItemType get_item_type () const override final { return ItemType::TUPLE_PAT; }
 
 protected:
@@ -645,6 +650,7 @@ public:
   Identifier get_identifier () const { return ident; }
 
   Pattern &get_pattern () { return *ident_pattern; }
+  Pattern &get_pattern () const { return *ident_pattern; }
 
 protected:
   /* Use covariance to implement clone function as returning this object rather
@@ -754,6 +760,12 @@ public:
   {
     return fields;
   }
+
+  const std::vector<std::unique_ptr<StructPatternField>> &
+  get_struct_pattern_fields () const
+  {
+    return fields;
+  }
 };
 
 // Struct pattern HIR node representation
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.