diff options
Diffstat (limited to 'crates/parser/src')
| -rw-r--r-- | crates/parser/src/grammar/expressions/atom.rs | 9 | ||||
| -rw-r--r-- | crates/parser/src/grammar/items.rs | 7 | ||||
| -rw-r--r-- | crates/parser/src/grammar/patterns.rs | 14 | ||||
| -rw-r--r-- | crates/parser/src/syntax_kind/generated.rs | 1 |
4 files changed, 29 insertions, 2 deletions
diff --git a/crates/parser/src/grammar/expressions/atom.rs b/crates/parser/src/grammar/expressions/atom.rs index e897d5a52f0..c7a3556a775 100644 --- a/crates/parser/src/grammar/expressions/atom.rs +++ b/crates/parser/src/grammar/expressions/atom.rs @@ -46,6 +46,7 @@ pub(super) const ATOM_EXPR_FIRST: TokenSet = T![continue], T![async], T![try], + T![const], T![loop], T![for], LIFETIME_IDENT, @@ -115,6 +116,14 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar block_expr(p); m.complete(p, EFFECT_EXPR) } + // test const_block + // fn f() { const { } } + T![const] if la == T!['{'] => { + let m = p.start(); + p.bump(T![const]); + block_expr(p); + m.complete(p, EFFECT_EXPR) + } T!['{'] => { // test for_range_from // fn foo() { diff --git a/crates/parser/src/grammar/items.rs b/crates/parser/src/grammar/items.rs index 8999829b437..72b73f89174 100644 --- a/crates/parser/src/grammar/items.rs +++ b/crates/parser/src/grammar/items.rs @@ -96,7 +96,10 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker) -> Result<(), Marker> { let mut has_mods = false; // modifiers - has_mods |= p.eat(T![const]); + if p.at(T![const]) && p.nth(1) != T!['{'] { + p.eat(T![const]); + has_mods = true; + } // test_err async_without_semicolon // fn foo() { let _ = async {} } @@ -167,7 +170,7 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker) -> Result<(), Marker> { m.complete(p, TRAIT); } - T![const] => { + T![const] if p.nth(1) != T!['{'] => { consts::konst(p, m); } diff --git a/crates/parser/src/grammar/patterns.rs b/crates/parser/src/grammar/patterns.rs index 7e7f73deeac..b53d5749f42 100644 --- a/crates/parser/src/grammar/patterns.rs +++ b/crates/parser/src/grammar/patterns.rs @@ -89,6 +89,7 @@ fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> { let m = match p.nth(0) { T![box] => box_pat(p), T![ref] | T![mut] => ident_pat(p, true), + T![const] => const_block_pat(p), IDENT => match p.nth(1) { // Checks the token after an IDENT to see if a pattern is a path (Struct { .. }) or macro // (T![x]). @@ -386,3 +387,16 @@ fn box_pat(p: &mut Parser) -> CompletedMarker { pattern_single(p); m.complete(p, BOX_PAT) } + +// test const_block_pat +// fn main() { +// let const { 15 } = (); +// let const { foo(); bar() } = (); +// } +fn const_block_pat(p: &mut Parser) -> CompletedMarker { + assert!(p.at(T![const])); + let m = p.start(); + p.bump(T![const]); + expressions::block_expr(p); + m.complete(p, CONST_BLOCK_PAT) +} diff --git a/crates/parser/src/syntax_kind/generated.rs b/crates/parser/src/syntax_kind/generated.rs index 980aa59794f..f69e71bdba6 100644 --- a/crates/parser/src/syntax_kind/generated.rs +++ b/crates/parser/src/syntax_kind/generated.rs @@ -170,6 +170,7 @@ pub enum SyntaxKind { RANGE_PAT, LITERAL_PAT, MACRO_PAT, + CONST_BLOCK_PAT, TUPLE_EXPR, ARRAY_EXPR, PAREN_EXPR, |
