diff options
| author | Josh Triplett <josh@joshtriplett.org> | 2025-07-06 15:15:01 -0700 |
|---|---|---|
| committer | Josh Triplett <josh@joshtriplett.org> | 2025-08-08 11:00:54 -0700 |
| commit | bad0d45b2dc2b2be36e9e82604a6c3dd95dba08a (patch) | |
| tree | 161e336b95a92df8aabd2da30d516c7a0527f5e5 /tests/ui/parser | |
| parent | 2054a0c56b063c195d316e4ff44d0c9f8ad2c012 (diff) | |
| download | rust-bad0d45b2dc2b2be36e9e82604a6c3dd95dba08a.tar.gz rust-bad0d45b2dc2b2be36e9e82604a6c3dd95dba08a.zip | |
mbe: Parse macro attribute rules
This handles various kinds of errors, but does not allow applying the attributes yet. This adds the feature gate `macro_attr`.
Diffstat (limited to 'tests/ui/parser')
| -rw-r--r-- | tests/ui/parser/macro/macro-attr-bad.rs | 32 | ||||
| -rw-r--r-- | tests/ui/parser/macro/macro-attr-bad.stderr | 80 |
2 files changed, 112 insertions, 0 deletions
diff --git a/tests/ui/parser/macro/macro-attr-bad.rs b/tests/ui/parser/macro/macro-attr-bad.rs new file mode 100644 index 00000000000..4313a4d04ab --- /dev/null +++ b/tests/ui/parser/macro/macro-attr-bad.rs @@ -0,0 +1,32 @@ +#![crate_type = "lib"] +#![feature(macro_attr)] + +macro_rules! attr_incomplete_1 { attr } +//~^ ERROR macro definition ended unexpectedly + +macro_rules! attr_incomplete_2 { attr() } +//~^ ERROR macro definition ended unexpectedly + +macro_rules! attr_incomplete_3 { attr() {} } +//~^ ERROR expected `=>` + +macro_rules! attr_incomplete_4 { attr() {} => } +//~^ ERROR macro definition ended unexpectedly + +macro_rules! attr_noparens_1 { attr{} {} => {} } +//~^ ERROR macro attribute argument matchers require parentheses + +macro_rules! attr_noparens_2 { attr[] {} => {} } +//~^ ERROR macro attribute argument matchers require parentheses + +macro_rules! attr_noparens_3 { attr _ {} => {} } +//~^ ERROR invalid macro matcher + +macro_rules! attr_dup_matcher_1 { attr() {$x:ident $x:ident} => {} } +//~^ ERROR duplicate matcher binding + +macro_rules! attr_dup_matcher_2 { attr($x:ident $x:ident) {} => {} } +//~^ ERROR duplicate matcher binding + +macro_rules! attr_dup_matcher_3 { attr($x:ident) {$x:ident} => {} } +//~^ ERROR duplicate matcher binding diff --git a/tests/ui/parser/macro/macro-attr-bad.stderr b/tests/ui/parser/macro/macro-attr-bad.stderr new file mode 100644 index 00000000000..4d286b66649 --- /dev/null +++ b/tests/ui/parser/macro/macro-attr-bad.stderr @@ -0,0 +1,80 @@ +error: macro definition ended unexpectedly + --> $DIR/macro-attr-bad.rs:4:38 + | +LL | macro_rules! attr_incomplete_1 { attr } + | ^ expected macro attr args + +error: macro definition ended unexpectedly + --> $DIR/macro-attr-bad.rs:7:40 + | +LL | macro_rules! attr_incomplete_2 { attr() } + | ^ expected macro attr body + +error: expected `=>`, found end of macro arguments + --> $DIR/macro-attr-bad.rs:10:43 + | +LL | macro_rules! attr_incomplete_3 { attr() {} } + | ^ expected `=>` + +error: macro definition ended unexpectedly + --> $DIR/macro-attr-bad.rs:13:46 + | +LL | macro_rules! attr_incomplete_4 { attr() {} => } + | ^ expected right-hand side of macro rule + +error: macro attribute argument matchers require parentheses + --> $DIR/macro-attr-bad.rs:16:36 + | +LL | macro_rules! attr_noparens_1 { attr{} {} => {} } + | ^^ + | +help: the delimiters should be `(` and `)` + | +LL - macro_rules! attr_noparens_1 { attr{} {} => {} } +LL + macro_rules! attr_noparens_1 { attr() {} => {} } + | + +error: macro attribute argument matchers require parentheses + --> $DIR/macro-attr-bad.rs:19:36 + | +LL | macro_rules! attr_noparens_2 { attr[] {} => {} } + | ^^ + | +help: the delimiters should be `(` and `)` + | +LL - macro_rules! attr_noparens_2 { attr[] {} => {} } +LL + macro_rules! attr_noparens_2 { attr() {} => {} } + | + +error: invalid macro matcher; matchers must be contained in balanced delimiters + --> $DIR/macro-attr-bad.rs:22:37 + | +LL | macro_rules! attr_noparens_3 { attr _ {} => {} } + | ^ + +error: duplicate matcher binding + --> $DIR/macro-attr-bad.rs:25:52 + | +LL | macro_rules! attr_dup_matcher_1 { attr() {$x:ident $x:ident} => {} } + | -------- ^^^^^^^^ duplicate binding + | | + | previous binding + +error: duplicate matcher binding + --> $DIR/macro-attr-bad.rs:28:49 + | +LL | macro_rules! attr_dup_matcher_2 { attr($x:ident $x:ident) {} => {} } + | -------- ^^^^^^^^ duplicate binding + | | + | previous binding + +error: duplicate matcher binding + --> $DIR/macro-attr-bad.rs:31:51 + | +LL | macro_rules! attr_dup_matcher_3 { attr($x:ident) {$x:ident} => {} } + | -------- ^^^^^^^^ duplicate binding + | | + | previous binding + +error: aborting due to 10 previous errors + |
