]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Parse const with no value expression
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Mon, 23 Oct 2023 15:06:43 +0000 (17:06 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 18:09:25 +0000 (19:09 +0100)
Const with no value expression may exist either in trait or in disabled
blocks. This means we should be able to parse those correctly.

gcc/rust/ChangeLog:

* ast/rust-item.h: Add a new constructor for const with no value
expression.
* parse/rust-parse-impl.h (Parser::parse_const_item): Allow const with
no expression value.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/rust/ast/rust-item.h
gcc/rust/parse/rust-parse-impl.h

index b91e18dc03571413e6ed15ede3a0f97d02dee7f1..eba86dca2fa738f2b3d5c5134211d210ec672a55 100644 (file)
@@ -2604,6 +2604,13 @@ public:
       const_expr (std::move (const_expr)), locus (locus)
   {}
 
+  ConstantItem (std::string ident, Visibility vis, std::unique_ptr<Type> type,
+               std::vector<Attribute> outer_attrs, location_t locus)
+    : VisItem (std::move (vis), std::move (outer_attrs)),
+      identifier (std::move (ident)), type (std::move (type)),
+      const_expr (nullptr), locus (locus)
+  {}
+
   ConstantItem (ConstantItem const &other)
     : VisItem (other), identifier (other.identifier), locus (other.locus)
   {
index 7844f7214ad2984c44339e09a614c0ca70f4ff10..4738393fd429fd010627e5c3d94d5f0ca6e98c35 100644 (file)
@@ -4783,6 +4783,16 @@ Parser<ManagedTokenSource>::parse_const_item (AST::Visibility vis,
   // parse constant type (required)
   std::unique_ptr<AST::Type> type = parse_type ();
 
+  // A const with no given expression value
+  if (lexer.peek_token ()->get_id () == SEMICOLON)
+    {
+      lexer.skip_token ();
+      return std::unique_ptr<AST::ConstantItem> (
+       new AST::ConstantItem (std::move (ident), std::move (vis),
+                              std::move (type), std::move (outer_attrs),
+                              locus));
+    }
+
   if (!skip_token (EQUAL))
     {
       skip_after_semicolon ();