]> gcc.gnu.org Git - gcc.git/commitdiff
Fix lookup of TuplePattern sub-pattern types
authorOwen Avery <powerboat9.gamer@gmail.com>
Mon, 12 Feb 2024 23:20:19 +0000 (18:20 -0500)
committerCohenArthur <arthur.cohen@embecosm.com>
Tue, 13 Feb 2024 15:08:02 +0000 (15:08 +0000)
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
gcc/testsuite/rust/compile/issue-2847-b.rs [new file with mode: 0644]

index 810cf6bff64c7520abf2e42d5f6c992c985bf67d..df60fc01ce5439f617ce28151a819410f1502ce6 100644 (file)
@@ -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 (file)
index 0000000..ab26142
--- /dev/null
@@ -0,0 +1,4 @@
+pub fn test() -> i32 {
+    let (a, _) = (1, 2);
+    a
+}
This page took 0.073406 seconds and 5 git commands to generate.