From: Zhi Heng Date: Fri, 13 Jun 2025 14:45:23 +0000 (+0800) Subject: gccrs: Implement compilation of IdentifierPattern's subpattern bindings X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c11c65378d9a959fff53f0505e4457c239cfc6b8;p=thirdparty%2Fgcc.git 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 --- diff --git a/gcc/rust/backend/rust-compile-pattern.cc b/gcc/rust/backend/rust-compile-pattern.cc index e19aa678497..bd3aea01b53 100644 --- a/gcc/rust/backend/rust-compile-pattern.cc +++ b/gcc/rust/backend/rust-compile-pattern.cc @@ -666,6 +666,12 @@ CompilePatternBindings::visit (HIR::ReferencePattern &pattern) void CompilePatternBindings::visit (HIR::IdentifierPattern &pattern) { + if (pattern.has_subpattern ()) + { + CompilePatternBindings::Compile (pattern.get_subpattern (), + match_scrutinee_expr, ctx); + } + if (!pattern.get_is_ref ()) { ctx->insert_pattern_binding (pattern.get_mappings ().get_hirid (), diff --git a/gcc/testsuite/rust/compile/match-identifierpattern-enum.rs b/gcc/testsuite/rust/compile/match-identifierpattern-enum.rs new file mode 100644 index 00000000000..c712667e27a --- /dev/null +++ b/gcc/testsuite/rust/compile/match-identifierpattern-enum.rs @@ -0,0 +1,12 @@ +enum Foo { + I(i32), +} + +fn main() { + let x = Foo::I(1); + + match x { + a @ Foo::I(b) => {}, + _ => {}, + }; +} diff --git a/gcc/testsuite/rust/execute/match-identifierpattern-enum.rs b/gcc/testsuite/rust/execute/match-identifierpattern-enum.rs new file mode 100644 index 00000000000..c3a0f65fe71 --- /dev/null +++ b/gcc/testsuite/rust/execute/match-identifierpattern-enum.rs @@ -0,0 +1,15 @@ +enum Foo { + I(i32), +} + +fn main() -> i32 { + let x = Foo::I(0); + let ret = 1; + + match x { + _ @ Foo::I(b) => { ret = b }, + _ => {}, + }; + + ret +}