gccrs: Fix lookup of TuplePattern sub-pattern types

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>
This commit is contained in:
Owen Avery 2024-02-12 18:20:19 -05:00 committed by Arthur Cohen
parent d7dde4ba49
commit cdd7638241
2 changed files with 10 additions and 6 deletions

View 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

View file

@ -0,0 +1,4 @@
pub fn test() -> i32 {
let (a, _) = (1, 2);
a
}