]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Expect identifier subpatterns to be non-alt
authorOwen Avery <powerboat9.gamer@gmail.com>
Mon, 18 Aug 2025 23:03:11 +0000 (19:03 -0400)
committerArthur Cohen <arthur.cohen@embecosm.com>
Thu, 30 Oct 2025 19:58:41 +0000 (20:58 +0100)
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 <powerboat9.gamer@gmail.com>
gcc/rust/parse/rust-parse-impl.h
gcc/testsuite/rust/compile/parse_closure_bind.rs [new file with mode: 0644]

index 5694ec5951db80f57f820d23a4c2e5e2b197e098..90c4da4a4d3a176152fad8fff8cf049460021d65 100644 (file)
@@ -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 (file)
index 0000000..1e08197
--- /dev/null
@@ -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)
+}