Trimmed GIMPLE code gen for let-identifierpattern-subpattern.rs
...
RUSTTMP.1.__0 = 0;
RUSTTMP.1.__1 = 2;
RUSTTMP.1.__2 = 3;
bar = RUSTTMP.1.__0;
RUSTTMP.2 = RUSTTMP.1.__1;
RUSTTMP.3 = RUSTTMP.1.__2;
foo.__0 = 0;
foo.__1 = 2;
foo.__2 = 3;
ret = 1;
RUSTTMP.5 = foo;
_1 = RUSTTMP.5.__0;
_2 = _1 == 0;
_3 = RUSTTMP.5.__1;
_4 = _3 == 2;
_5 = _2 & _4;
_6 = RUSTTMP.5.__2;
_7 = _6 == 3;
_8 = _5 & _7;
if (_8 != 0) goto <D.143>; else goto <D.144>;
<D.143>:
{
{
ret = bar;
}
goto <D.137>;
}
...
gcc/rust/ChangeLog:
* backend/rust-compile-pattern.cc(CompilePatternLet::visit(IdentifierPattern)):
Add support for subpatterns.
* backend/rust-compile-var-decl.h(CompileVarDecl::visit(IdentifierPattern)):
Implement compilation for subpatterns.
Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
}
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);
}
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
--- /dev/null
+fn main() -> i32 {
+ let foo @ (bar, _, _) = (0, 2, 3);
+ let mut ret = 1;
+
+ match foo {
+ (0, 2, 3) => { ret = bar },
+ _ => {}
+ }
+
+ ret
+}
\ No newline at end of file