From 87ddc07e7a4c459422b51c7a2322a4df879a33f2 Mon Sep 17 00:00:00 2001 From: Owen Avery Date: Mon, 18 Aug 2025 19:03:11 -0400 Subject: [PATCH] gccrs: Expect identifier subpatterns to be non-alt 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 --- 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::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::parse_ident_leading_pattern () // identifier with pattern bind lexer.skip_token (); - std::unique_ptr bind_pattern = parse_pattern (); + std::unique_ptr 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 { + /// 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.47.3