aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_parser/src/grammar
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-09-15 08:02:51 +0100
committerGitHub <[email protected]>2019-09-15 08:02:51 +0100
commitbcdba777bdc43762cff73ac3ded4ae737a503692 (patch)
treee65797200723aeb35afc10acb24a7a7d385d5c2b /crates/ra_parser/src/grammar
parent211171ffe6a4e8cbf31b9513972e59a8b9bdc811 (diff)
parentc413f444a02ad7898b7a259e0d7aeaed91fd1997 (diff)
Merge #1847
1847: Allow an underscore as the identifier in `const` items r=matklad a=ecstatic-morse [RFC 2526](https://github.com/rust-lang/rust/issues/54912) was recently stabilized, meaning `const _: i32 = 5;` is now a valid item. Co-authored-by: Dylan MacKenzie <[email protected]>
Diffstat (limited to 'crates/ra_parser/src/grammar')
-rw-r--r--crates/ra_parser/src/grammar/items.rs2
-rw-r--r--crates/ra_parser/src/grammar/items/consts.rs11
2 files changed, 11 insertions, 2 deletions
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> {
258 } 258 }
259 T![enum] => nominal::enum_def(p, m), 259 T![enum] => nominal::enum_def(p, m),
260 T![use] => use_item::use_item(p, m), 260 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),
262 T![static] => consts::static_def(p, m), 262 T![static] => consts::static_def(p, m),
263 // test extern_block 263 // test extern_block
264 // extern {} 264 // 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) {
12 assert!(p.at(kw)); 12 assert!(p.at(kw));
13 p.bump_any(); 13 p.bump_any();
14 p.eat(T![mut]); // FIXME: validator to forbid const mut 14 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
16 types::ascription(p); 25 types::ascription(p);
17 if p.eat(T![=]) { 26 if p.eat(T![=]) {
18 expressions::expr(p); 27 expressions::expr(p);