1
Fork 0

Rollup merge of #125276 - dev-ardi:no-main-diag, r=fmease

Fix parsing of erroneously placed semicolons

This closes https://github.com/rust-lang/rust/issues/124935, is a continuation of https://github.com/rust-lang/rust/pull/125245 after rebasing https://github.com/rust-lang/rust/pull/125117.

Thanks ```@gurry``` for your code and sorry for making it confusing :P

r? fmease
This commit is contained in:
Matthias Krüger 2024-05-21 20:28:47 +02:00 committed by GitHub
commit bfa98d318f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 42 additions and 7 deletions

View file

@ -58,9 +58,15 @@ impl<'a> Parser<'a> {
let attrs = self.parse_inner_attributes()?;
let post_attr_lo = self.token.span;
let mut items = ThinVec::new();
while let Some(item) = self.parse_item(ForceCollect::No)? {
self.maybe_consume_incorrect_semicolon(Some(&item));
let mut items: ThinVec<P<_>> = ThinVec::new();
// There shouldn't be any stray semicolons before or after items.
// `parse_item` consumes the appropriate semicolons so any leftover is an error.
loop {
while self.maybe_consume_incorrect_semicolon(items.last().map(|x| &**x)) {} // Eat all bad semicolons
let Some(item) = self.parse_item(ForceCollect::No)? else {
break;
};
items.push(item);
}