Skip to content

Commit 2c94c49

Browse files
committed
Parse const effect block
1 parent 03a9bba commit 2c94c49

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

crates/parser/src/grammar/expressions/atom.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ pub(super) const ATOM_EXPR_FIRST: TokenSet =
4646
T![continue],
4747
T![async],
4848
T![try],
49+
T![const],
4950
T![loop],
5051
T![for],
5152
LIFETIME_IDENT,
@@ -115,6 +116,14 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar
115116
block_expr(p);
116117
m.complete(p, EFFECT_EXPR)
117118
}
119+
// test const_block
120+
// fn f() { const { } }
121+
T![const] if la == T!['{'] => {
122+
let m = p.start();
123+
p.bump(T![const]);
124+
block_expr(p);
125+
m.complete(p, EFFECT_EXPR)
126+
}
118127
T!['{'] => {
119128
// test for_range_from
120129
// fn foo() {

crates/parser/src/grammar/items.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker) -> Result<(), Marker> {
9696
let mut has_mods = false;
9797

9898
// modifiers
99-
has_mods |= p.eat(T![const]);
99+
if p.at(T![const]) && p.nth(1) != T!['{'] {
100+
p.eat(T![const]);
101+
has_mods = true;
102+
}
100103

101104
// test_err async_without_semicolon
102105
// fn foo() { let _ = async {} }
@@ -167,7 +170,7 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker) -> Result<(), Marker> {
167170
m.complete(p, TRAIT);
168171
}
169172

170-
T![const] => {
173+
T![const] if p.nth(1) != T!['{'] => {
171174
consts::konst(p, m);
172175
}
173176

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fn f() { const { } }

0 commit comments

Comments
 (0)