address review comments

This commit is contained in:
Deadbeef
2025-08-22 13:06:49 +08:00
parent 30bb7045d6
commit 4970127c33
15 changed files with 30 additions and 35 deletions

View File

@@ -2228,11 +2228,10 @@ pub(crate) struct KeywordLifetime {
}
#[derive(Diagnostic)]
#[diag(parse_invalid_label)]
pub(crate) struct InvalidLabel {
#[diag(parse_keyword_label)]
pub(crate) struct KeywordLabel {
#[primary_span]
pub span: Span,
pub name: String,
}
#[derive(Diagnostic)]

View File

@@ -3094,13 +3094,7 @@ impl<'a> Parser<'a> {
if let Some((ident, is_raw)) = self.token.lifetime() {
// Disallow `'fn`, but with a better error message than `expect_lifetime`.
if matches!(is_raw, IdentIsRaw::No) && ident.without_first_quote().is_reserved() {
self.dcx().emit_err(errors::InvalidLabel {
span: ident.span,
// `IntoDiagArg` prints the symbol as if it was an ident,
// so `'break` is printed as `r#break`. We don't want that
// here so convert to string eagerly.
name: ident.without_first_quote().name.to_string(),
});
self.dcx().emit_err(errors::KeywordLabel { span: ident.span });
}
self.bump();

View File

@@ -1479,8 +1479,7 @@ impl<'a> Parser<'a> {
pub(super) fn expect_lifetime(&mut self) -> Lifetime {
if let Some((ident, is_raw)) = self.token.lifetime() {
if matches!(is_raw, IdentIsRaw::No)
&& ident.without_first_quote().is_reserved()
&& ![kw::UnderscoreLifetime, kw::StaticLifetime].contains(&ident.name)
&& ident.without_first_quote().is_reserved_lifetime()
{
self.dcx().emit_err(errors::KeywordLifetime { span: ident.span });
}