-
Notifications
You must be signed in to change notification settings - Fork 164
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
Conversation
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>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
// 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)); | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 :)
Fixes #2665.