Allow an underscore as the identifier in const items

This commit is contained in:
Dylan MacKenzie 2019-09-14 15:59:24 -07:00
parent 211171ffe6
commit 253a18f938
3 changed files with 12 additions and 2 deletions

View File

@ -258,7 +258,7 @@ fn items_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> {
}
T![enum] => nominal::enum_def(p, m),
T![use] => use_item::use_item(p, m),
T![const] if (la == IDENT || la == T![mut]) => consts::const_def(p, m),
T![const] if (la == IDENT || la == T![_] || la == T![mut]) => consts::const_def(p, m),
T![static] => consts::static_def(p, m),
// test extern_block
// extern {}

View File

@ -12,7 +12,16 @@ fn const_or_static(p: &mut Parser, m: Marker, kw: SyntaxKind, def: SyntaxKind) {
assert!(p.at(kw));
p.bump_any();
p.eat(T![mut]); // FIXME: validator to forbid const mut
name(p);
// Allow `_` in place of an identifier in a `const`.
let is_const_underscore = kw == T![const] && p.eat(T![_]);
if !is_const_underscore {
name(p);
}
// test_err static_underscore
// static _: i32 = 5;
types::ascription(p);
if p.eat(T![=]) {
expressions::expr(p);

View File

@ -0,0 +1 @@
static _: i32 = 5;