From: Owen Avery <[email protected]>

Fixes https://github.com/Rust-GCC/gccrs/issues/4071.

gcc/rust/ChangeLog:

        * parse/rust-parse-impl.h (Parser::parse_identifier_pattern):
        Use parse_pattern_no_alt to parse identifier pattern
        subpatterns.
        (Parser::parse_ident_leading_pattern): Likewise.

gcc/testsuite/ChangeLog:

        * rust/compile/parse_closure_bind.rs: New test.

Signed-off-by: Owen Avery <[email protected]>
---
 gcc/rust/parse/rust-parse-impl.h              |  5 +++--
 .../rust/compile/parse_closure_bind.rs        | 19 +++++++++++++++++++
 2 files changed, 22 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/rust/compile/parse_closure_bind.rs

diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index 5694ec5951d..90c4da4a4d3 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -11113,7 +11113,7 @@ Parser<ManagedTokenSource>::parse_identifier_pattern ()
       lexer.skip_token ();
 
       // parse required pattern to bind
-      bind_pattern = parse_pattern ();
+      bind_pattern = parse_pattern_no_alt ();
       if (bind_pattern == nullptr)
        {
          Error error (lexer.peek_token ()->get_locus (),
@@ -11240,7 +11240,8 @@ Parser<ManagedTokenSource>::parse_ident_leading_pattern 
()
            // identifier with pattern bind
            lexer.skip_token ();
 
-           std::unique_ptr<AST::Pattern> bind_pattern = parse_pattern ();
+           std::unique_ptr<AST::Pattern> bind_pattern
+             = parse_pattern_no_alt ();
            if (bind_pattern == nullptr)
              {
                Error error (
diff --git a/gcc/testsuite/rust/compile/parse_closure_bind.rs 
b/gcc/testsuite/rust/compile/parse_closure_bind.rs
new file mode 100644
index 00000000000..1e08197a5fd
--- /dev/null
+++ b/gcc/testsuite/rust/compile/parse_closure_bind.rs
@@ -0,0 +1,19 @@
+// { dg-additional-options "-frust-compile-until=typecheck" }
+// TODO: this should typecheck
+
+#[lang = "sized"]
+trait Sized {}
+
+#[lang = "fn_once"]
+pub trait FnOnce<Args> {
+    /// The returned type after the call operator is used.
+    #[lang = "fn_once_output"]
+    type Output;
+
+    /// Performs the call operation.
+    extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
+}
+
+pub fn foo() {
+    (|_a @ _b| {}) (1)
+}
-- 
2.50.1

Reply via email to