diff --git a/crates/hir_def/src/macro_expansion_tests/mbe/matching.rs b/crates/hir_def/src/macro_expansion_tests/mbe/matching.rs index 83e8937f5b..b93072d446 100644 --- a/crates/hir_def/src/macro_expansion_tests/mbe/matching.rs +++ b/crates/hir_def/src/macro_expansion_tests/mbe/matching.rs @@ -85,17 +85,21 @@ fn stmt_boundaries() { check( r#" macro_rules! m { - ($($s:stmt)*) => (stringify!($($s |)*)) + ($($s:stmt)*) => (stringify!($($s |)*);) } -// +errors m!(;;92;let x = 92; loop {};); "#, expect![[r#" macro_rules! m { - ($($s:stmt)*) => (stringify!($($s |)*)) + ($($s:stmt)*) => (stringify!($($s |)*);) } -/* error: expected Stmt *//* parse error: expected SEMICOLON */ -stringify!() +stringify!(; +|; +|92|; +|let x = 92|; +|loop {} +|; +|); "#]], ); } diff --git a/crates/parser/src/grammar.rs b/crates/parser/src/grammar.rs index b704242065..e1a265d817 100644 --- a/crates/parser/src/grammar.rs +++ b/crates/parser/src/grammar.rs @@ -98,11 +98,6 @@ pub(crate) mod entry { let m = p.start(); while !p.at(EOF) { - if p.at(T![;]) { - p.bump(T![;]); - continue; - } - expressions::stmt(p, expressions::Semicolon::Optional); } diff --git a/crates/parser/src/grammar/expressions.rs b/crates/parser/src/grammar/expressions.rs index c585fdb096..9dbba89c56 100644 --- a/crates/parser/src/grammar/expressions.rs +++ b/crates/parser/src/grammar/expressions.rs @@ -30,6 +30,10 @@ fn expr_no_struct(p: &mut Parser) { } pub(super) fn stmt(p: &mut Parser, semicolon: Semicolon) { + if p.eat(T![;]) { + return; + } + let m = p.start(); // test attr_on_expr_stmt // fn foo() { @@ -143,12 +147,6 @@ pub(super) fn expr_block_contents(p: &mut Parser) { // fn f() {}; // struct S {}; // } - - if p.at(T![;]) { - p.bump(T![;]); - continue; - } - stmt(p, Semicolon::Required); } } diff --git a/crates/parser/src/shortcuts.rs b/crates/parser/src/shortcuts.rs index e14526aa73..7040608a9f 100644 --- a/crates/parser/src/shortcuts.rs +++ b/crates/parser/src/shortcuts.rs @@ -76,8 +76,7 @@ impl<'a> LexedStr<'a> { builder.eat_trivias(); (builder.sink)(StrStep::Exit); } - State::PendingEnter => (), - State::Normal => unreachable!(), + State::PendingEnter | State::Normal => (), } let is_eof = builder.pos == builder.lexed.len(); @@ -101,9 +100,8 @@ enum State { impl Builder<'_, '_> { fn token(&mut self, kind: SyntaxKind, n_tokens: u8) { match mem::replace(&mut self.state, State::Normal) { - State::PendingEnter => unreachable!(), State::PendingExit => (self.sink)(StrStep::Exit), - State::Normal => (), + State::PendingEnter | State::Normal => (), } self.eat_trivias(); self.do_token(kind, n_tokens as usize);