Skip to content

Commit 083af83

Browse files
committed
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 c3ca1b9 commit 083af83

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
@@ -8206,7 +8206,14 @@ Parser<ManagedTokenSource>::parse_while_let_loop_expr (
82068206
// parse predicate patterns
82078207
std::vector<std::unique_ptr<AST::Pattern>> predicate_patterns
82088208
= parse_match_arm_patterns (EQUAL);
8209-
// TODO: have to ensure that there is at least 1 pattern?
8209+
// ensure that there is at least 1 pattern
8210+
if (!predicate_patterns.size ())
8211+
{
8212+
Error error (lexer.peek_token ()->get_locus (),
8213+
"should be at least 1 pattern");
8214+
add_error (std::move (error));
8215+
return nullptr;
8216+
}
82108217

82118218
if (!skip_token (EQUAL))
82128219
{
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)