Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions gcc/rust/parse/rust-parse-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -10484,16 +10484,22 @@ Parser<ManagedTokenSource>::parse_pattern ()
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));
Expand Down
7 changes: 7 additions & 0 deletions gcc/testsuite/rust/compile/issue-4155.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
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 }
}],
}
Loading