From: Arthur Cohen Date: Wed, 19 Apr 2023 15:40:15 +0000 (+0200) Subject: gccrs: parser: Parse reference patterns correctly X-Git-Tag: basepoints/gcc-15~2642 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=94f2a1ce4b582e250b8a760a2acdd77cf98dd454;p=thirdparty%2Fgcc.git gccrs: parser: Parse reference patterns correctly Reference patterns cannot contain AltPatterns per the Rust reference, so we should not call into `parse_pattern` to parse the referenced pattern, but rather the more restrictive `parse_pattern_no_alt`. gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_reference_pattern): Do not call into `parse_pattern` anymore. gcc/testsuite/ChangeLog: * rust/compile/issue-1807.rs: New test. --- diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 13f05419f41d..c3aeda2e7c0b 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -10949,7 +10949,7 @@ Parser::parse_reference_pattern () } // parse pattern to get reference of (required) - std::unique_ptr pattern = parse_pattern (); + std::unique_ptr pattern = parse_pattern_no_alt (); if (pattern == nullptr) { Error error (lexer.peek_token ()->get_locus (), diff --git a/gcc/testsuite/rust/compile/issue-1807.rs b/gcc/testsuite/rust/compile/issue-1807.rs new file mode 100644 index 000000000000..fe821f0fc903 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-1807.rs @@ -0,0 +1,6 @@ +// { dg-additional-options "-fsyntax-only" } + +fn main() { + let is_zero = &|&&d: &&u8| -> bool { d == b'0' }; + let lambda = |&c| c != b'9'; +}