diff options
| author | Deadbeef <ent3rm4n@gmail.com> | 2025-08-04 09:42:27 +0000 |
|---|---|---|
| committer | Deadbeef <ent3rm4n@gmail.com> | 2025-08-22 12:58:37 +0800 |
| commit | 30bb7045d6b80b979b235396626f3b405cfec160 (patch) | |
| tree | 68a541040bfccf7c834f9469b7e41cfb359aca90 /compiler/rustc_parse | |
| parent | 1e5b5ba1e732d557f00a3cd79150990370c7db0a (diff) | |
| download | rust-30bb7045d6b80b979b235396626f3b405cfec160.tar.gz rust-30bb7045d6b80b979b235396626f3b405cfec160.zip | |
don't print invalid labels with `r#`
Diffstat (limited to 'compiler/rustc_parse')
| -rw-r--r-- | compiler/rustc_parse/src/errors.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 8 |
2 files changed, 8 insertions, 2 deletions
diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index 2c046329e33..7d84fc2a2f9 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -2232,7 +2232,7 @@ pub(crate) struct KeywordLifetime { pub(crate) struct InvalidLabel { #[primary_span] pub span: Span, - pub name: Symbol, + pub name: String, } #[derive(Diagnostic)] diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index cb7f755f524..effcfd54a8f 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -3094,7 +3094,13 @@ 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, name: ident.name }); + 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.bump(); |
