-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: better error cases with bad/missing identifiers in MBEs
- Loading branch information
1 parent
f9d52dc
commit 4c4b155
Showing
16 changed files
with
130 additions
and
98 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,13 @@ | ||
error: macros that expand to items must be delimited with braces or followed by a semicolon | ||
error: expected identifier, found `(` | ||
--> $DIR/issue-118786.rs:7:22 | ||
| | ||
LL | macro_rules! $macro_name { | ||
| ^^^^^^^^^^^ | ||
| ^^^^^^^^^^^ expected identifier | ||
| | ||
help: change the delimiters to curly braces | ||
help: try removing the parenthesis around the name for this `macro_rules!` | ||
| | ||
LL | macro_rules! {} { | ||
| ~ + | ||
help: add a semicolon | ||
| | ||
LL | macro_rules! $macro_name; { | ||
| + | ||
|
||
error: macro expansion ignores token `{` and any following | ||
--> $DIR/issue-118786.rs:7:34 | ||
| | ||
LL | macro_rules! $macro_name { | ||
| ^ | ||
... | ||
LL | make_macro!((meow)); | ||
| ------------------- caused by the macro expansion here | ||
| | ||
= note: the usage of `make_macro!` is likely invalid in item context | ||
|
||
error: cannot find macro `macro_rules` in this scope | ||
--> $DIR/issue-118786.rs:7:9 | ||
| | ||
LL | macro_rules! $macro_name { | ||
| ^^^^^^^^^^^ | ||
... | ||
LL | make_macro!((meow)); | ||
| ------------------- in this macro invocation | ||
| | ||
note: maybe you have forgotten to define a name for this `macro_rules!` | ||
--> $DIR/issue-118786.rs:7:9 | ||
| | ||
LL | macro_rules! $macro_name { | ||
| ^^^^^^^^^^^ | ||
... | ||
LL | make_macro!((meow)); | ||
| ------------------- in this macro invocation | ||
= note: this error originates in the macro `make_macro` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
LL | macro_rules! meow { | ||
| ~~~~ | ||
|
||
error: aborting due to 3 previous errors | ||
error: aborting due to 1 previous error | ||
|
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Ensures MBEs with a missing ident produce a readable error | ||
|
||
macro_rules! { | ||
//~^ ERROR: expected identifier, found `{` | ||
//~| HELP: maybe you have forgotten to define a name for this `macro_rules!` | ||
() => {} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
error: expected identifier, found `{` | ||
--> $DIR/mbe-missing-ident-error.rs:3:14 | ||
| | ||
LL | macro_rules! { | ||
| ^ expected identifier | ||
| | ||
= help: maybe you have forgotten to define a name for this `macro_rules!` | ||
|
||
error: aborting due to 1 previous error | ||
|
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Ensures MBEs with a invalid ident produce a readable error | ||
|
||
macro_rules! (meepmeep) { | ||
//~^ ERROR: expected identifier, found `(` | ||
//~| HELP: try removing the parenthesis around the name for this `macro_rules!` | ||
() => {} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
error: expected identifier, found `(` | ||
--> $DIR/mbe-parenthesis-ident-error.rs:3:14 | ||
| | ||
LL | macro_rules! (meepmeep) { | ||
| ^ expected identifier | ||
| | ||
help: try removing the parenthesis around the name for this `macro_rules!` | ||
| | ||
LL | macro_rules! meepmeep { | ||
| ~~~~~~~~ | ||
|
||
error: aborting due to 1 previous error | ||
|
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,9 +1,8 @@ | ||
// check-pass | ||
// check-fail | ||
|
||
macro_rules! macro_rules { () => { struct S; } } // OK | ||
macro_rules! macro_rules { () => {} } | ||
//~^ ERROR: user-defined macros may not be named `macro_rules` | ||
|
||
macro_rules! {} // OK, calls the macro defined above | ||
|
||
fn main() { | ||
let s = S; | ||
} | ||
macro_rules! {} | ||
//~^ ERROR: expected identifier, found `{` | ||
//~| HELP: maybe you have forgotten to define a name for this `macro_rules!` |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
error: user-defined macros may not be named `macro_rules` | ||
--> $DIR/user-defined-macro-rules.rs:3:14 | ||
| | ||
LL | macro_rules! macro_rules { () => {} } | ||
| ^^^^^^^^^^^ | ||
|
||
error: expected identifier, found `{` | ||
--> $DIR/user-defined-macro-rules.rs:6:14 | ||
| | ||
LL | macro_rules! {} | ||
| ^ expected identifier | ||
| | ||
= help: maybe you have forgotten to define a name for this `macro_rules!` | ||
|
||
error: aborting due to 2 previous errors | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.