diff mbox series

[COMMITTED,7/9] gccrs: Fix lookup of TuplePattern sub-pattern types

Message ID 20240221131636.3336103-10-arthur.cohen@embecosm.com
State New
Headers show
Series [COMMITTED,1/9] gccrs: Fix typo in RegionConstraints instance | expand

Commit Message

Arthur Cohen Feb. 21, 2024, 1:15 p.m. UTC
From: Owen Avery <powerboat9.gamer@gmail.com>

gcc/rust/ChangeLog:

	* backend/rust-compile-pattern.cc
	(CompilePatternLet::visit):
	Lookup type of sub-pattern, not tuple pattern itself.

gcc/testsuite/ChangeLog:

	* rust/compile/issue-2847-b.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
---
 gcc/rust/backend/rust-compile-pattern.cc   | 12 ++++++------
 gcc/testsuite/rust/compile/issue-2847-b.rs |  4 ++++
 2 files changed, 10 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/rust/compile/issue-2847-b.rs
diff mbox series

Patch

diff --git a/gcc/rust/backend/rust-compile-pattern.cc b/gcc/rust/backend/rust-compile-pattern.cc
index 4fa611f5383..1a32f02c3ea 100644
--- a/gcc/rust/backend/rust-compile-pattern.cc
+++ b/gcc/rust/backend/rust-compile-pattern.cc
@@ -678,8 +678,8 @@  CompilePatternLet::visit (HIR::TuplePattern &pattern)
 	for (auto &sub : items_lower)
 	  {
 	    TyTy::BaseType *ty_sub = nullptr;
-	    HirId pattern_id = pattern.get_mappings ().get_hirid ();
-	    bool ok = ctx->get_tyctx ()->lookup_type (pattern_id, &ty_sub);
+	    HirId sub_id = sub->get_mappings ().get_hirid ();
+	    bool ok = ctx->get_tyctx ()->lookup_type (sub_id, &ty_sub);
 	    rust_assert (ok);
 
 	    tree sub_init
@@ -697,8 +697,8 @@  CompilePatternLet::visit (HIR::TuplePattern &pattern)
 	for (auto &sub : items_upper)
 	  {
 	    TyTy::BaseType *ty_sub = nullptr;
-	    HirId pattern_id = pattern.get_mappings ().get_hirid ();
-	    bool ok = ctx->get_tyctx ()->lookup_type (pattern_id, &ty_sub);
+	    HirId sub_id = sub->get_mappings ().get_hirid ();
+	    bool ok = ctx->get_tyctx ()->lookup_type (sub_id, &ty_sub);
 	    rust_assert (ok);
 
 	    tree sub_init
@@ -719,8 +719,8 @@  CompilePatternLet::visit (HIR::TuplePattern &pattern)
 	for (auto &sub : items.get_patterns ())
 	  {
 	    TyTy::BaseType *ty_sub = nullptr;
-	    HirId pattern_id = pattern.get_mappings ().get_hirid ();
-	    bool ok = ctx->get_tyctx ()->lookup_type (pattern_id, &ty_sub);
+	    HirId sub_id = sub->get_mappings ().get_hirid ();
+	    bool ok = ctx->get_tyctx ()->lookup_type (sub_id, &ty_sub);
 	    rust_assert (ok);
 
 	    tree sub_init
diff --git a/gcc/testsuite/rust/compile/issue-2847-b.rs b/gcc/testsuite/rust/compile/issue-2847-b.rs
new file mode 100644
index 00000000000..ab2614210fc
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-2847-b.rs
@@ -0,0 +1,4 @@ 
+pub fn test() -> i32 {
+    let (a, _) = (1, 2);
+    a
+}