From 253a18f93893ffa0e2804937c913fed84df5f8d3 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Sat, 14 Sep 2019 15:59:24 -0700 Subject: Allow an underscore as the identifier in `const` items --- crates/ra_parser/src/grammar/items.rs | 2 +- crates/ra_parser/src/grammar/items/consts.rs | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'crates/ra_parser/src/grammar') diff --git a/crates/ra_parser/src/grammar/items.rs b/crates/ra_parser/src/grammar/items.rs index eff9d67e4..4dd80d443 100644 --- a/crates/ra_parser/src/grammar/items.rs +++ b/crates/ra_parser/src/grammar/items.rs @@ -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 {} diff --git a/crates/ra_parser/src/grammar/items/consts.rs b/crates/ra_parser/src/grammar/items/consts.rs index e11546333..63e0e6e0c 100644 --- a/crates/ra_parser/src/grammar/items/consts.rs +++ b/crates/ra_parser/src/grammar/items/consts.rs @@ -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); -- cgit v1.2.3