public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] parser: Add 0 sized slice pattern parsing
@ 2023-03-05 11:42 Thomas Schwinge
0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2023-03-05 11:42 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:baf5c546b59058fcc5aac430e8fbe6e99d355634
commit baf5c546b59058fcc5aac430e8fbe6e99d355634
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date: Wed Mar 1 18:46:33 2023 +0100
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>
Diff:
---
gcc/rust/parse/rust-parse-impl.h | 9 ++++++++-
gcc/testsuite/rust/compile/zero_sized_slice.rs | 5 +++++
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index 15effaa1979..b17744fedaa 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 00000000000..cd1e21e7b33
--- /dev/null
+++ b/gcc/testsuite/rust/compile/zero_sized_slice.rs
@@ -0,0 +1,5 @@
+// { dg-options "-fsyntax-only" }
+
+fn foo() {
+ let [] = [0; 0];
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-03-05 11:42 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-05 11:42 [gcc/devel/rust/master] parser: Add 0 sized slice pattern parsing Thomas Schwinge
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).