Deny keyword lifetimes pre-expansion

This commit is contained in:
Michael Goulet 2024-06-20 16:36:35 -04:00
parent a91f7d72f1
commit d0a1851ec2
14 changed files with 99 additions and 70 deletions

View file

@ -2932,10 +2932,17 @@ impl<'a> Parser<'a> {
}
pub(crate) fn eat_label(&mut self) -> Option<Label> {
self.token.lifetime().map(|ident| {
if let Some(ident) = self.token.lifetime() {
// Disallow `'fn`, but with a better error message than `expect_lifetime`.
if ident.without_first_quote().is_reserved() {
self.dcx().emit_err(errors::InvalidLabel { span: ident.span, name: ident.name });
}
self.bump();
Label { ident }
})
Some(Label { ident })
} else {
None
}
}
/// Parses a `match ... { ... }` expression (`match` token already eaten).