Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse const with no value #2708

Merged
merged 2 commits into from
Oct 23, 2023
Merged

Conversation

P-E-P
Copy link
Member

@P-E-P P-E-P commented Oct 23, 2023

Fixes #2665.

P-E-P added 2 commits October 23, 2023 17:10
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>
Highlight issue 2665's fix for const with no value expression.

gcc/testsuite/ChangeLog:

	* rust/compile/issue-2665.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
@P-E-P P-E-P added this to the GCC 14.1 release milestone Oct 23, 2023
@P-E-P P-E-P requested a review from CohenArthur October 23, 2023 15:19
@P-E-P P-E-P self-assigned this Oct 23, 2023
@P-E-P P-E-P marked this pull request as ready for review October 23, 2023 15:19
@P-E-P P-E-P changed the title Parse const no value Parse const with no value Oct 23, 2023
Copy link
Member

@CohenArthur CohenArthur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Comment on lines +4786 to +4794
// 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));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is good, but we need to handle it somewhere else, right? e.g. the rest of the AST and HIR are probably expecting that an impl's const always has a value, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, this ICEs:

struct S;

impl S {
    const D: u8;
}

while it should produce a nice error: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=9b8643a863d5350e8b226e8bc9789b88

this should be adressed in a later PR however :)

@P-E-P P-E-P added this pull request to the merge queue Oct 23, 2023
Merged via the queue into Rust-GCC:master with commit eb393ac Oct 23, 2023
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Cannot parse disabled const in impl
2 participants