diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2023-03-01 18:46:33 +0100 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 18:19:02 +0100 |
commit | ba5445ad7ad438e84004aa5da6c15bfc4cccf2fd (patch) | |
tree | 4b3ec1fc4e6269122688f459bae30247259b7431 /gcc | |
parent | 060652cdd8b1fda6d108c87f421e78a885d5c173 (diff) | |
download | gcc-ba5445ad7ad438e84004aa5da6c15bfc4cccf2fd.zip gcc-ba5445ad7ad438e84004aa5da6c15bfc4cccf2fd.tar.gz gcc-ba5445ad7ad438e84004aa5da6c15bfc4cccf2fd.tar.bz2 |
gccrs: parser: Add 0 sized slice pattern parsing
Check for a closing square bracket before attempting to parse any
pattern within a slice. Also add a new test to verify zero sized
slice parsing.
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h (Parser::parse_slice_pattern): Add
closing square bracket check.
gcc/testsuite/ChangeLog:
* rust/compile/zero_sized_slice.rs: New test.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/parse/rust-parse-impl.h | 9 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/zero_sized_slice.rs | 5 |
2 files changed, 13 insertions, 1 deletions
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 37b3244..c6267b2 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -11136,8 +11136,16 @@ std::unique_ptr<AST::SlicePattern> Parser<ManagedTokenSource>::parse_slice_pattern () { Location square_locus = lexer.peek_token ()->get_locus (); + std::vector<std::unique_ptr<AST::Pattern>> patterns; skip_token (LEFT_SQUARE); + if (lexer.peek_token ()->get_id () == RIGHT_SQUARE) + { + skip_token (RIGHT_SQUARE); + return std::unique_ptr<AST::SlicePattern> ( + new AST::SlicePattern (std::move (patterns), square_locus)); + } + // parse initial pattern (required) std::unique_ptr<AST::Pattern> initial_pattern = parse_pattern (); if (initial_pattern == nullptr) @@ -11149,7 +11157,6 @@ Parser<ManagedTokenSource>::parse_slice_pattern () return nullptr; } - std::vector<std::unique_ptr<AST::Pattern>> patterns; patterns.push_back (std::move (initial_pattern)); const_TokenPtr t = lexer.peek_token (); diff --git a/gcc/testsuite/rust/compile/zero_sized_slice.rs b/gcc/testsuite/rust/compile/zero_sized_slice.rs new file mode 100644 index 0000000..cd1e21e --- /dev/null +++ b/gcc/testsuite/rust/compile/zero_sized_slice.rs @@ -0,0 +1,5 @@ +// { dg-options "-fsyntax-only" } + +fn foo() { + let [] = [0; 0]; +} |