Skip to content

Commit 253a18f

Browse files
Allow an underscore as the identifier in const items
1 parent 211171f commit 253a18f

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

crates/ra_parser/src/grammar/items.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ fn items_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> {
258258
}
259259
T![enum] => nominal::enum_def(p, m),
260260
T![use] => use_item::use_item(p, m),
261-
T![const] if (la == IDENT || la == T![mut]) => consts::const_def(p, m),
261+
T![const] if (la == IDENT || la == T![_] || la == T![mut]) => consts::const_def(p, m),
262262
T![static] => consts::static_def(p, m),
263263
// test extern_block
264264
// extern {}

crates/ra_parser/src/grammar/items/consts.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,16 @@ fn const_or_static(p: &mut Parser, m: Marker, kw: SyntaxKind, def: SyntaxKind) {
1212
assert!(p.at(kw));
1313
p.bump_any();
1414
p.eat(T![mut]); // FIXME: validator to forbid const mut
15-
name(p);
15+
16+
// Allow `_` in place of an identifier in a `const`.
17+
let is_const_underscore = kw == T![const] && p.eat(T![_]);
18+
if !is_const_underscore {
19+
name(p);
20+
}
21+
22+
// test_err static_underscore
23+
// static _: i32 = 5;
24+
1625
types::ascription(p);
1726
if p.eat(T![=]) {
1827
expressions::expr(p);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
static _: i32 = 5;

0 commit comments

Comments
 (0)