Fix parse error message for meta items#124778
Merged
bors merged 1 commit intorust-lang:masterfrom May 10, 2024
Merged
Conversation
Collaborator
fmease
commented
May 5, 2024
| @@ -1,17 +1,25 @@ | |||
| //@ compile-flags: -Zdeduplicate-diagnostics=yes | |||
| //@ run-rustfix | |||
Member
Author
There was a problem hiding this comment.
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.
Contributor
|
r? compiler |
Contributor
|
r? compiler |
nnethercote
reviewed
May 10, 2024
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 |
Contributor
There was a problem hiding this comment.
Suggested change
| .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 |
?
Member
Author
There was a problem hiding this comment.
Good suggestion, the current wording is roundabout.
Contributor
|
r=me with the suggestion considered. Thanks! |
7f0d04b to
de57ef7
Compare
de57ef7 to
0ad3c5d
Compare
Member
Author
|
@bors r=nnethercote rollup |
Collaborator
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this pull request
May 10, 2024
…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.
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
May 10, 2024
…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
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
May 10, 2024
…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
rust-timer
added a commit
to rust-lang-ci/rust
that referenced
this pull request
May 10, 2024
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.
GuillaumeGomez
pushed a commit
to GuillaumeGomez/rust
that referenced
this pull request
Jul 10, 2024
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses #122796 (comment), cc [@]Thomasdezeeuw.
For attrs inside of a macro like
#[doc(alias = $ident)]or#[cfg(feature = $ident)]where$identis 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&truebut not arbitrary identifiers.Furthermore, we used to suggest garbage when encountering unexpected non-identifier tokens:
Now we no longer do.