Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions gcc/rust/backend/rust-compile-pattern.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
9 changes: 9 additions & 0 deletions gcc/rust/backend/rust-compile-var-decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ class CompileVarDecl : public HIRCompileBase, public HIR::HIRPatternVisitor
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
Expand Down
5 changes: 5 additions & 0 deletions gcc/rust/typecheck/rust-hir-type-check-pattern.cc
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,11 @@ ClosureParamInfer::visit (HIR::WildcardPattern &pattern)
void
ClosureParamInfer::visit (HIR::IdentifierPattern &pattern)
{
if (pattern.has_subpattern ())
{
ClosureParamInfer::Resolve (pattern.get_subpattern ());
}

HirId id = pattern.get_mappings ().get_hirid ();
infered = new TyTy::InferType (id, TyTy::InferType::InferTypeKind::GENERAL,
TyTy::InferType::TypeHint::Default (),
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Loading