Skip to content

Commit f87c5a6

Browse files
Polygonalrphilberty
authored andcommitted
gccrs: Implement compilation of IdentifierPattern's subpattern bindings
gcc/rust/ChangeLog: * backend/rust-compile-pattern.cc: Add support for IdentifierPattern's subpattern under CompilePatternBindings. Signed-off-by: Yap Zhi Heng <[email protected]>
1 parent add42e3 commit f87c5a6

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

gcc/rust/backend/rust-compile-pattern.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,12 @@ CompilePatternBindings::visit (HIR::ReferencePattern &pattern)
666666
void
667667
CompilePatternBindings::visit (HIR::IdentifierPattern &pattern)
668668
{
669+
if (pattern.has_subpattern ())
670+
{
671+
CompilePatternBindings::Compile (pattern.get_subpattern (),
672+
match_scrutinee_expr, ctx);
673+
}
674+
669675
if (!pattern.get_is_ref ())
670676
{
671677
ctx->insert_pattern_binding (pattern.get_mappings ().get_hirid (),
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
enum Foo {
2+
I(i32),
3+
}
4+
5+
fn main() {
6+
let x = Foo::I(1);
7+
8+
match x {
9+
a @ Foo::I(b) => {},
10+
_ => {},
11+
};
12+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
enum Foo {
2+
I(i32),
3+
}
4+
5+
fn main() -> i32 {
6+
let x = Foo::I(0);
7+
let ret = 1;
8+
9+
match x {
10+
_ @ Foo::I(b) => { ret = b },
11+
_ => {},
12+
};
13+
14+
ret
15+
}

0 commit comments

Comments
 (0)