Skip to content

Commit b536992

Browse files
committed
parse empty statemet as statemetn
1 parent 841cd30 commit b536992

File tree

4 files changed

+15
-20
lines changed

4 files changed

+15
-20
lines changed

crates/hir_def/src/macro_expansion_tests/mbe/matching.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,21 @@ fn stmt_boundaries() {
8585
check(
8686
r#"
8787
macro_rules! m {
88-
($($s:stmt)*) => (stringify!($($s |)*))
88+
($($s:stmt)*) => (stringify!($($s |)*);)
8989
}
90-
// +errors
9190
m!(;;92;let x = 92; loop {};);
9291
"#,
9392
expect![[r#"
9493
macro_rules! m {
95-
($($s:stmt)*) => (stringify!($($s |)*))
94+
($($s:stmt)*) => (stringify!($($s |)*);)
9695
}
97-
/* error: expected Stmt *//* parse error: expected SEMICOLON */
98-
stringify!()
96+
stringify!(;
97+
|;
98+
|92|;
99+
|let x = 92|;
100+
|loop {}
101+
|;
102+
|);
99103
"#]],
100104
);
101105
}

crates/parser/src/grammar.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,6 @@ pub(crate) mod entry {
9898
let m = p.start();
9999

100100
while !p.at(EOF) {
101-
if p.at(T![;]) {
102-
p.bump(T![;]);
103-
continue;
104-
}
105-
106101
expressions::stmt(p, expressions::Semicolon::Optional);
107102
}
108103

crates/parser/src/grammar/expressions.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ fn expr_no_struct(p: &mut Parser) {
3030
}
3131

3232
pub(super) fn stmt(p: &mut Parser, semicolon: Semicolon) {
33+
if p.eat(T![;]) {
34+
return;
35+
}
36+
3337
let m = p.start();
3438
// test attr_on_expr_stmt
3539
// fn foo() {
@@ -143,12 +147,6 @@ pub(super) fn expr_block_contents(p: &mut Parser) {
143147
// fn f() {};
144148
// struct S {};
145149
// }
146-
147-
if p.at(T![;]) {
148-
p.bump(T![;]);
149-
continue;
150-
}
151-
152150
stmt(p, Semicolon::Required);
153151
}
154152
}

crates/parser/src/shortcuts.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ impl<'a> LexedStr<'a> {
7676
builder.eat_trivias();
7777
(builder.sink)(StrStep::Exit);
7878
}
79-
State::PendingEnter => (),
80-
State::Normal => unreachable!(),
79+
State::PendingEnter | State::Normal => (),
8180
}
8281

8382
let is_eof = builder.pos == builder.lexed.len();
@@ -101,9 +100,8 @@ enum State {
101100
impl Builder<'_, '_> {
102101
fn token(&mut self, kind: SyntaxKind, n_tokens: u8) {
103102
match mem::replace(&mut self.state, State::Normal) {
104-
State::PendingEnter => unreachable!(),
105103
State::PendingExit => (self.sink)(StrStep::Exit),
106-
State::Normal => (),
104+
State::PendingEnter | State::Normal => (),
107105
}
108106
self.eat_trivias();
109107
self.do_token(kind, n_tokens as usize);

0 commit comments

Comments
 (0)