From: Yap Zhi Heng <[email protected]>

Trimmed GIMPLE code gen for let-identifierpattern-subpattern.rs

...
      RUSTTMP.1.__0 = 0;
      RUSTTMP.1.__1 = 2;
      RUSTTMP.1.__2 = 3;
      bar = RUSTTMP.1.__0;
      RUSTTMP.2 = RUSTTMP.1.__1;
      RUSTTMP.3 = RUSTTMP.1.__2;
      foo.__0 = 0;
      foo.__1 = 2;
      foo.__2 = 3;
      ret = 1;
      RUSTTMP.5 = foo;
      _1 = RUSTTMP.5.__0;
      _2 = _1 == 0;
      _3 = RUSTTMP.5.__1;
      _4 = _3 == 2;
      _5 = _2 & _4;
      _6 = RUSTTMP.5.__2;
      _7 = _6 == 3;
      _8 = _5 & _7;
      if (_8 != 0) goto <D.143>; else goto <D.144>;
      <D.143>:
      {
        {
          ret = bar;
        }
        goto <D.137>;
      }
...

gcc/rust/ChangeLog:

        * 
backend/rust-compile-pattern.cc(CompilePatternLet::visit(IdentifierPattern)):
        Add support for subpatterns.
        * 
backend/rust-compile-var-decl.h(CompileVarDecl::visit(IdentifierPattern)):
        Implement compilation for subpatterns.

Signed-off-by: Yap Zhi Heng <[email protected]>
---
 gcc/rust/backend/rust-compile-pattern.cc              |  5 +++++
 gcc/rust/backend/rust-compile-var-decl.h              |  9 +++++++++
 .../torture/let-identifierpattern-subpattern.rs       | 11 +++++++++++
 3 files changed, 25 insertions(+)
 create mode 100644 
gcc/testsuite/rust/execute/torture/let-identifierpattern-subpattern.rs

diff --git a/gcc/rust/backend/rust-compile-pattern.cc 
b/gcc/rust/backend/rust-compile-pattern.cc
index 16f8b52679c..577f8de9c93 100644
--- a/gcc/rust/backend/rust-compile-pattern.cc
+++ b/gcc/rust/backend/rust-compile-pattern.cc
@@ -992,6 +992,11 @@ CompilePatternLet::visit (HIR::IdentifierPattern &pattern)
     }
   else
     {
+      if (pattern.has_subpattern ())
+       {
+         CompilePatternLet::Compile (&pattern.get_subpattern (), init_expr, ty,
+                                     rval_locus, ctx);
+       }
       auto s = Backend::init_statement (fnctx.fndecl, var, init_expr);
       ctx->add_statement (s);
     }
diff --git a/gcc/rust/backend/rust-compile-var-decl.h 
b/gcc/rust/backend/rust-compile-var-decl.h
index 4ab02a8b760..15f3ebb3a6a 100644
--- a/gcc/rust/backend/rust-compile-var-decl.h
+++ b/gcc/rust/backend/rust-compile-var-decl.h
@@ -64,6 +64,15 @@ public:
     ctx->insert_var_decl (stmt_id, var);
 
     vars.push_back (var);
+
+    if (pattern.has_subpattern ())
+      {
+       auto subpattern_vars
+         = CompileVarDecl::compile (fndecl, translated_type,
+                                    &pattern.get_subpattern (), ctx);
+       vars.insert (vars.end (), subpattern_vars.begin (),
+                    subpattern_vars.end ());
+      }
   }
 
   void visit (HIR::TuplePattern &pattern) override
diff --git 
a/gcc/testsuite/rust/execute/torture/let-identifierpattern-subpattern.rs 
b/gcc/testsuite/rust/execute/torture/let-identifierpattern-subpattern.rs
new file mode 100644
index 00000000000..fa1f56e60b5
--- /dev/null
+++ b/gcc/testsuite/rust/execute/torture/let-identifierpattern-subpattern.rs
@@ -0,0 +1,11 @@
+fn main() -> i32 {
+    let foo @ (bar, _, _) = (0, 2, 3);
+    let mut ret = 1;
+
+    match foo {
+        (0, 2, 3) => { ret = bar },
+        _ => {}
+    }
+
+    ret
+}
\ No newline at end of file
-- 
2.50.1

Reply via email to