Skip to content

Commit

Permalink
Parse const with no value expression
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
P-E-P committed Oct 23, 2023
1 parent af3071f commit 4f0da0e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions gcc/rust/ast/rust-item.h
Original file line number Diff line number Diff line change
Expand Up @@ -2604,6 +2604,13 @@ class ConstantItem : public VisItem,
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)
{
Expand Down
10 changes: 10 additions & 0 deletions gcc/rust/parse/rust-parse-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand Down

0 comments on commit 4f0da0e

Please sign in to comment.