https://gcc.gnu.org/g:87ddc07e7a4c459422b51c7a2322a4df879a33f2
commit r16-4798-g87ddc07e7a4c459422b51c7a2322a4df879a33f2 Author: Owen Avery <[email protected]> Date: Mon Aug 18 19:03:11 2025 -0400 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 <[email protected]> Diff: --- gcc/rust/parse/rust-parse-impl.h | 5 +++-- gcc/testsuite/rust/compile/parse_closure_bind.rs | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 5694ec5951db..90c4da4a4d3a 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 000000000000..1e08197a5fd0 --- /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) +}
