From: Pierre-Emmanuel Patry Date: Mon, 23 Oct 2023 15:06:43 +0000 (+0200) Subject: gccrs: Parse const with no value expression X-Git-Tag: basepoints/gcc-15~2066 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=91732258cedf367ac0f4dbe75aef7d0e22d46b3a;p=thirdparty%2Fgcc.git gccrs: Parse const with no value expression 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 --- diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index b91e18dc0357..eba86dca2fa7 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -2604,6 +2604,13 @@ public: const_expr (std::move (const_expr)), locus (locus) {} + ConstantItem (std::string ident, Visibility vis, std::unique_ptr type, + std::vector 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) { diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 7844f7214ad2..4738393fd429 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -4783,6 +4783,16 @@ Parser::parse_const_item (AST::Visibility vis, // parse constant type (required) std::unique_ptr type = parse_type (); + // A const with no given expression value + if (lexer.peek_token ()->get_id () == SEMICOLON) + { + lexer.skip_token (); + return std::unique_ptr ( + new AST::ConstantItem (std::move (ident), std::move (vis), + std::move (type), std::move (outer_attrs), + locus)); + } + if (!skip_token (EQUAL)) { skip_after_semicolon ();