https://gcc.gnu.org/g:735ac41b5c3c0bd2cf2bfa63292221e53f85ddb7

commit r16-4845-g735ac41b5c3c0bd2cf2bfa63292221e53f85ddb7
Author: Yap Zhi Heng <[email protected]>
Date:   Thu Aug 28 11:26:03 2025 +0800

    gccrs: Implement missing read-only checker case for TuplePatternItemsHasRest
    
    gcc/rust/ChangeLog:
    
            * checks/errors/rust-readonly-check.cc (collect_assignment_tuple): 
Implement
            read-only checker for tuple patterns with rest pattern.
    
    Signed-off-by: Yap Zhi Heng <[email protected]>

Diff:
---
 gcc/rust/checks/errors/rust-readonly-check.cc            | 14 ++++++++++++--
 gcc/testsuite/rust/compile/tuplepattern-rest-readonly.rs |  5 +++++
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/checks/errors/rust-readonly-check.cc 
b/gcc/rust/checks/errors/rust-readonly-check.cc
index ed4145e56487..f484047e60b8 100644
--- a/gcc/rust/checks/errors/rust-readonly-check.cc
+++ b/gcc/rust/checks/errors/rust-readonly-check.cc
@@ -144,14 +144,24 @@ ReadonlyChecker::collect_assignment_tuple (TuplePattern 
&tuple_pattern,
     {
     case HIR::TuplePatternItems::ItemType::NO_REST:
       {
-       auto &items = static_cast<HIR::TuplePatternItemsNoRest &> (
+       auto &items_no_rest = static_cast<HIR::TuplePatternItemsNoRest &> (
          tuple_pattern.get_items ());
-       for (auto &sub : items.get_patterns ())
+       for (auto &sub : items_no_rest.get_patterns ())
          {
            collect_assignment (*sub, has_init_expr);
          }
       }
       break;
+    case HIR::TuplePatternItems::ItemType::HAS_REST:
+      {
+       auto &items_has_rest = static_cast<HIR::TuplePatternItemsHasRest &> (
+         tuple_pattern.get_items ());
+       for (auto &sub : items_has_rest.get_lower_patterns ())
+         collect_assignment (*sub, has_init_expr);
+       for (auto &sub : items_has_rest.get_upper_patterns ())
+         collect_assignment (*sub, has_init_expr);
+      }
+      break;
     default:
       break;
     }
diff --git a/gcc/testsuite/rust/compile/tuplepattern-rest-readonly.rs 
b/gcc/testsuite/rust/compile/tuplepattern-rest-readonly.rs
new file mode 100644
index 000000000000..db165ef4f264
--- /dev/null
+++ b/gcc/testsuite/rust/compile/tuplepattern-rest-readonly.rs
@@ -0,0 +1,5 @@
+fn main() {
+    let (a, .., b) = (1, 1);
+    a = 2; // { dg-error "assignment of read-only variable .a." }
+    b = 2; // { dg-error "assignment of read-only variable .b." }
+}
\ No newline at end of file

Reply via email to