forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#124778 - fmease:fix-diag-msg-parse-meta-ite…
…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.
- Loading branch information
Showing
13 changed files
with
93 additions
and
78 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
macro_rules! mac { | ||
($attr_item: meta) => { | ||
#[cfg($attr_item)] | ||
//~^ ERROR expected unsuffixed literal or identifier, found `an(arbitrary token stream)` | ||
//~| ERROR expected unsuffixed literal or identifier, found `an(arbitrary token stream)` | ||
//~^ ERROR expected unsuffixed literal, found `an(arbitrary token stream)` | ||
//~| ERROR expected unsuffixed literal, found `an(arbitrary token stream)` | ||
struct S; | ||
} | ||
} | ||
|
||
mac!(an(arbitrary token stream)); | ||
|
||
#[cfg(feature = -1)] | ||
//~^ ERROR expected unsuffixed literal, found `-` | ||
//~| ERROR expected unsuffixed literal, found `-` | ||
fn handler() {} | ||
|
||
fn main() {} |
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,25 @@ | ||
//@ compile-flags: -Zdeduplicate-diagnostics=yes | ||
//@ run-rustfix | ||
|
||
#![allow(unexpected_cfgs)] | ||
|
||
fn main() { | ||
#[cfg(key=foo)] | ||
//~^ ERROR expected unsuffixed literal, found `foo` | ||
//~| HELP surround the identifier with quotation marks to parse it as a string | ||
//~| HELP surround the identifier with quotation marks to make it into a string literal | ||
println!(); | ||
#[cfg(key="bar")] | ||
println!(); | ||
#[cfg(key=foo bar baz)] | ||
//~^ ERROR expected unsuffixed literal, found `foo` | ||
//~| HELP surround the identifier with quotation marks to parse it as a string | ||
//~| HELP surround the identifier with quotation marks to make it into a string literal | ||
println!(); | ||
} | ||
|
||
// Don't suggest surrounding `$name` or `nickname` with quotes: | ||
|
||
macro_rules! make { | ||
($name:ident) => { #[doc(alias = $name)] pub struct S; } | ||
//~^ ERROR expected unsuffixed literal, found `nickname` | ||
} | ||
|
||
make!(nickname); //~ NOTE in this expansion |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,35 @@ | ||
error: expected unsuffixed literal, found `foo` | ||
--> $DIR/attr-unquoted-ident.rs:7:15 | ||
--> $DIR/attr-unquoted-ident.rs:6:15 | ||
| | ||
LL | #[cfg(key=foo)] | ||
| ^^^ | ||
| | ||
help: surround the identifier with quotation marks to parse it as a string | ||
help: surround the identifier with quotation marks to make it into a string literal | ||
| | ||
LL | #[cfg(key="foo")] | ||
| + + | ||
|
||
error: expected unsuffixed literal, found `foo` | ||
--> $DIR/attr-unquoted-ident.rs:13:15 | ||
--> $DIR/attr-unquoted-ident.rs:12:15 | ||
| | ||
LL | #[cfg(key=foo bar baz)] | ||
| ^^^ | ||
| | ||
help: surround the identifier with quotation marks to parse it as a string | ||
help: surround the identifier with quotation marks to make it into a string literal | ||
| | ||
LL | #[cfg(key="foo bar baz")] | ||
| + + | ||
|
||
error: aborting due to 2 previous errors | ||
error: expected unsuffixed literal, found `nickname` | ||
--> $DIR/attr-unquoted-ident.rs:21:38 | ||
| | ||
LL | ($name:ident) => { #[doc(alias = $name)] pub struct S; } | ||
| ^^^^^ | ||
... | ||
LL | make!(nickname); | ||
| --------------- in this macro invocation | ||
| | ||
= note: this error originates in the macro `make` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: aborting due to 3 previous errors | ||
|