diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index fecff6153f39..3ea7dd48d1d1 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -14445,12 +14445,17 @@ Parser::parse_closure_expr_pratt (const_TokenPtr tok, if (lexer.peek_token ()->get_id () != COMMA) { + if (lexer.peek_token ()->get_id () == OR) + lexer.split_current_token (PIPE, PIPE); // not an error but means param list is done break; } // skip comma lexer.skip_token (); + if (lexer.peek_token ()->get_id () == OR) + lexer.split_current_token (PIPE, PIPE); + t = lexer.peek_token (); } diff --git a/gcc/testsuite/rust/compile/closure_in_closure.rs b/gcc/testsuite/rust/compile/closure_in_closure.rs new file mode 100644 index 000000000000..1a003070f6a7 --- /dev/null +++ b/gcc/testsuite/rust/compile/closure_in_closure.rs @@ -0,0 +1,8 @@ +// { dg-additional-options "-frust-compile-until=ast" } +// +// Do not reformat this test! The default rust format settings will insert a +// space between closure parameter lists. +fn main() { + let f = |_||x, y| x+y; + assert_eq!(f(())(1, 2), 3); +}