Skip to content

Commit 33d0494

Browse files
lucasly-baphilberty
authored andcommitted
gccrs: fix ICE on missing pattern in while loop
Adds a proper check for missing patterns in while expressions. Fixes #4162 gcc/rust/ChangeLog: * parse/rust-parse-impl.h(Parser<ManagedTokenSource>::parse_while_let_loop_expr): Add check for missing pattern. gcc/testsuite/ChangeLog: * rust/compile/issue-4162.rs: New test. Signed-off-by: Lucas Ly Ba <[email protected]>
1 parent 95e08b8 commit 33d0494

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

gcc/rust/parse/rust-parse-impl.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8234,7 +8234,14 @@ Parser<ManagedTokenSource>::parse_while_let_loop_expr (
82348234
// parse predicate patterns
82358235
std::vector<std::unique_ptr<AST::Pattern>> predicate_patterns
82368236
= parse_match_arm_patterns (EQUAL);
8237-
// TODO: have to ensure that there is at least 1 pattern?
8237+
// ensure that there is at least 1 pattern
8238+
if (predicate_patterns.empty ())
8239+
{
8240+
Error error (lexer.peek_token ()->get_locus (),
8241+
"should be at least 1 pattern");
8242+
add_error (std::move (error));
8243+
return nullptr;
8244+
}
82388245

82398246
if (!skip_token (EQUAL))
82408247
{
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
pub fn main() {
2+
while let = 5
3+
// { dg-error "should be at least 1 pattern" "" { target *-*-* } .-1 }
4+
// { dg-error "failed to parse statement or expression in block expression" "" { target *-*-* } .-2 }
5+
// { dg-error "unrecognised token .=. for start of item" "" { target *-*-* } .-3 }
6+
// { dg-error "failed to parse item in crate" "" { target *-*-* } .-4 }
7+
{}
8+
}
9+

0 commit comments

Comments
 (0)