https://gcc.gnu.org/g:c11c65378d9a959fff53f0505e4457c239cfc6b8
commit r16-2876-gc11c65378d9a959fff53f0505e4457c239cfc6b8 Author: Zhi Heng <yapz...@gmail.com> Date: Fri Jun 13 22:45:23 2025 +0800 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 <yapz...@gmail.com> Diff: --- gcc/rust/backend/rust-compile-pattern.cc | 6 ++++++ .../rust/compile/match-identifierpattern-enum.rs | 12 ++++++++++++ .../rust/execute/match-identifierpattern-enum.rs | 15 +++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/gcc/rust/backend/rust-compile-pattern.cc b/gcc/rust/backend/rust-compile-pattern.cc index e19aa678497d..bd3aea01b537 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 000000000000..c712667e27a4 --- /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 000000000000..c3a0f65fe710 --- /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 +}