diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-05-10 16:10:45 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-10 16:10:45 +0200 |
| commit | f605174ea7826fa3db67aa0b707758440656b44c (patch) | |
| tree | 057aa06a9919ea2484b4e89ee428b86f68282bea /compiler/rustc_parse/src/errors.rs | |
| parent | c768a0e99f93f150b58fc926e0e761c3e226cfc6 (diff) | |
| parent | 0ad3c5da72469c848e321ddee207f9a5dfbf9876 (diff) | |
| download | rust-f605174ea7826fa3db67aa0b707758440656b44c.tar.gz rust-f605174ea7826fa3db67aa0b707758440656b44c.zip | |
Rollup merge of #124778 - fmease:fix-diag-msg-parse-meta-item, r=nnethercote
Fix parse error message for meta items Addresses https://github.com/rust-lang/rust/issues/122796#issuecomment-2010803906, cc [``@]Thomasdezeeuw.`` For attrs inside of a macro like `#[doc(alias = $ident)]` or `#[cfg(feature = $ident)]` where `$ident` is a macro metavariable of fragment kind `ident`, we used to say the following when expanded (with `$ident` ⟼ `ident`): ``` error: expected unsuffixed literal or identifier, found `ident` --> weird.rs:6:19 | 6 | #[cfg(feature = $ident)] | ^^^^^^ ... 11 | m!(id); | ------ in this macro invocation | = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) ``` This was incorrect and caused confusion, justifiably so (see #122796). In this position, we only accept/expect *unsuffixed literals* which consist of numeric & string literals as well as the boolean literals / the keywords / the reserved identifiers `false` & `true` **but not** arbitrary identifiers. Furthermore, we used to suggest garbage when encountering unexpected non-identifier tokens: ``` error: expected unsuffixed literal, found `-` --> weird.rs:16:17 | 16 | #[cfg(feature = -1)] | ^ | help: surround the identifier with quotation marks to parse it as a string | 16 | #[cfg(feature =" "-1)] | + + ``` Now we no longer do.
Diffstat (limited to 'compiler/rustc_parse/src/errors.rs')
| -rw-r--r-- | compiler/rustc_parse/src/errors.rs | 14 |
1 files changed, 3 insertions, 11 deletions
diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index d06f03a7c17..2f68a299f26 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -978,21 +978,13 @@ pub(crate) struct InvalidMetaItem { #[primary_span] pub span: Span, pub token: Token, -} - -#[derive(Diagnostic)] -#[diag(parse_invalid_meta_item_unquoted_ident)] -pub(crate) struct InvalidMetaItemUnquotedIdent { - #[primary_span] - pub span: Span, - pub token: Token, #[subdiagnostic] - pub sugg: InvalidMetaItemSuggQuoteIdent, + pub quote_ident_sugg: Option<InvalidMetaItemQuoteIdentSugg>, } #[derive(Subdiagnostic)] -#[multipart_suggestion(parse_suggestion, applicability = "machine-applicable")] -pub(crate) struct InvalidMetaItemSuggQuoteIdent { +#[multipart_suggestion(parse_quote_ident_sugg, applicability = "machine-applicable")] +pub(crate) struct InvalidMetaItemQuoteIdentSugg { #[suggestion_part(code = "\"")] pub before: Span, #[suggestion_part(code = "\"")] |
