Skip to content

Commit

Permalink
Fix lookup of TuplePattern sub-pattern types
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
powerboat9 authored and CohenArthur committed Feb 13, 2024
1 parent 50f8ca9 commit a471675
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 6 additions & 6 deletions gcc/rust/backend/rust-compile-pattern.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions gcc/testsuite/rust/compile/issue-2847-b.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub fn test() -> i32 {
let (a, _) = (1, 2);
a
}

0 comments on commit a471675

Please sign in to comment.