-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix parse error message for meta items #124778
Conversation
@@ -1,17 +1,25 @@ | |||
//@ compile-flags: -Zdeduplicate-diagnostics=yes | |||
//@ run-rustfix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed the rustfix directive since I've added a negative test case and didn't want to add revisions (do they work in combination with rustfix?) or a separate test file.
f1ce7e9
to
89736c2
Compare
This comment has been minimized.
This comment has been minimized.
89736c2
to
7f0d04b
Compare
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
r? compiler |
r? compiler |
compiler/rustc_parse/messages.ftl
Outdated
parse_invalid_meta_item_unquoted_ident = expected unsuffixed literal, found `{$token}` | ||
.suggestion = surround the identifier with quotation marks to parse it as a string | ||
parse_invalid_meta_item = expected unsuffixed literal, found `{$token}` | ||
.quote_ident_sugg = surround the identifier with quotation marks to make it parse as a string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.quote_ident_sugg = surround the identifier with quotation marks to make it parse as a string | |
.quote_ident_sugg = surround the identifier with quotation marks to make it into a string |
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestion, the current wording is roundabout.
r=me with the suggestion considered. Thanks! |
7f0d04b
to
de57ef7
Compare
de57ef7
to
0ad3c5d
Compare
@bors r=nnethercote rollup |
…m, r=nnethercote Fix parse error message for meta items Addresses rust-lang#122796 (comment), 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 rust-lang#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.
…iaskrgr Rollup of 4 pull requests Successful merges: - rust-lang#124615 (coverage: Further simplify extraction of mapping info from MIR) - rust-lang#124778 (Fix parse error message for meta items) - rust-lang#124807 (Migrate `run-make/rustdoc-io-error` to `rmake.rs`) - rust-lang#124957 (Make `Ty::builtin_deref` just return a `Ty`) Failed merges: - rust-lang#124888 (Migrate `run-make/rustdoc-output-path` to rmake) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 5 pull requests Successful merges: - rust-lang#124615 (coverage: Further simplify extraction of mapping info from MIR) - rust-lang#124778 (Fix parse error message for meta items) - rust-lang#124797 (Refactor float `Primitive`s to a separate `Float` type) - rust-lang#124888 (Migrate `run-make/rustdoc-output-path` to rmake) - rust-lang#124957 (Make `Ty::builtin_deref` just return a `Ty`) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#124778 - fmease:fix-diag-msg-parse-meta-item, r=nnethercote Fix parse error message for meta items Addresses rust-lang#122796 (comment), 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 rust-lang#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.
…iaskrgr Rollup of 5 pull requests Successful merges: - rust-lang#124615 (coverage: Further simplify extraction of mapping info from MIR) - rust-lang#124778 (Fix parse error message for meta items) - rust-lang#124797 (Refactor float `Primitive`s to a separate `Float` type) - rust-lang#124888 (Migrate `run-make/rustdoc-output-path` to rmake) - rust-lang#124957 (Make `Ty::builtin_deref` just return a `Ty`) r? `@ghost` `@rustbot` modify labels: rollup
Addresses #122796 (comment), cc [@]Thomasdezeeuw.
For attrs inside of a macro like
#[doc(alias = $ident)]
or#[cfg(feature = $ident)]
where$ident
is a macro metavariable of fragment kindident
, we used to say the following when expanded (with$ident
⟼ident
):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:
Now we no longer do.