Fixes https://github.com/Rust-GCC/gccrs/issues/4155.
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h (Parser::parse_pattern): Ignore
inner patterns which fail to parse.
gcc/testsuite/ChangeLog:
* rust/compile/issue-4155.rs: New test.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
return first;
std::vector<std::unique_ptr<AST::Pattern>> alts;
- alts.push_back (std::move (first));
+ if (first != nullptr)
+ alts.push_back (std::move (first));
do
{
lexer.skip_token ();
- alts.push_back (parse_pattern_no_alt ());
+ auto follow = parse_pattern_no_alt ();
+ if (follow != nullptr)
+ alts.push_back (std::move (follow));
}
while (lexer.peek_token ()->get_id () == PIPE);
+ if (alts.empty ())
+ return nullptr;
+
/* alternates */
return std::unique_ptr<AST::Pattern> (
new AST::AltPattern (std::move (alts), start_locus));
--- /dev/null
+struct Bug {
+ inner: [(); match Vec::new {
+ f @ |n() => 1
+// { dg-error "failed to parse pattern to bind" "" { target *-*-* } .-1 }
+// { dg-error "unexpected token .|. in pattern" "" { target *-*-* } .-2 }
+ }],
+}