summaryrefslogtreecommitdiffstats
path: root/tests/ui/parser/macro
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/parser/macro')
-rw-r--r--tests/ui/parser/macro/bad-macro-argument.stderr2
-rw-r--r--tests/ui/parser/macro/issue-37113.stderr2
-rw-r--r--tests/ui/parser/macro/issue-37234.stderr2
-rw-r--r--tests/ui/parser/macro/macro-doc-comments-1.stderr2
-rw-r--r--tests/ui/parser/macro/macro-doc-comments-2.stderr2
-rw-r--r--tests/ui/parser/macro/macro-expand-to-field.rs79
-rw-r--r--tests/ui/parser/macro/macro-expand-to-field.stderr71
-rw-r--r--tests/ui/parser/macro/macro-expand-to-match-arm.rs20
-rw-r--r--tests/ui/parser/macro/macro-expand-to-match-arm.stderr20
-rw-r--r--tests/ui/parser/macro/macro-repeat.stderr2
10 files changed, 197 insertions, 5 deletions
diff --git a/tests/ui/parser/macro/bad-macro-argument.stderr b/tests/ui/parser/macro/bad-macro-argument.stderr
index 3cd8accb6..ba6499d71 100644
--- a/tests/ui/parser/macro/bad-macro-argument.stderr
+++ b/tests/ui/parser/macro/bad-macro-argument.stderr
@@ -4,5 +4,5 @@ error: expected expression, found end of macro arguments
LL | println!("Hello, {}", message/);
| ^ expected expression
-error: aborting due to previous error
+error: aborting due to 1 previous error
diff --git a/tests/ui/parser/macro/issue-37113.stderr b/tests/ui/parser/macro/issue-37113.stderr
index da9e743a0..1f2fe2310 100644
--- a/tests/ui/parser/macro/issue-37113.stderr
+++ b/tests/ui/parser/macro/issue-37113.stderr
@@ -12,5 +12,5 @@ LL | test_macro!(String,);
= help: enum variants can be `Variant`, `Variant = <integer>`, `Variant(Type, ..., TypeN)` or `Variant { fields: Types }`
= note: this error originates in the macro `test_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
-error: aborting due to previous error
+error: aborting due to 1 previous error
diff --git a/tests/ui/parser/macro/issue-37234.stderr b/tests/ui/parser/macro/issue-37234.stderr
index d79196204..cd91ea441 100644
--- a/tests/ui/parser/macro/issue-37234.stderr
+++ b/tests/ui/parser/macro/issue-37234.stderr
@@ -9,5 +9,5 @@ LL | failed!();
|
= note: this error originates in the macro `failed` (in Nightly builds, run with -Z macro-backtrace for more info)
-error: aborting due to previous error
+error: aborting due to 1 previous error
diff --git a/tests/ui/parser/macro/macro-doc-comments-1.stderr b/tests/ui/parser/macro/macro-doc-comments-1.stderr
index eaeb62d2c..9d2d1bc00 100644
--- a/tests/ui/parser/macro/macro-doc-comments-1.stderr
+++ b/tests/ui/parser/macro/macro-doc-comments-1.stderr
@@ -16,5 +16,5 @@ note: while trying to match `[`
LL | (#[$outer:meta]) => ()
| ^
-error: aborting due to previous error
+error: aborting due to 1 previous error
diff --git a/tests/ui/parser/macro/macro-doc-comments-2.stderr b/tests/ui/parser/macro/macro-doc-comments-2.stderr
index 1dcd95f6f..22efd995b 100644
--- a/tests/ui/parser/macro/macro-doc-comments-2.stderr
+++ b/tests/ui/parser/macro/macro-doc-comments-2.stderr
@@ -16,5 +16,5 @@ note: while trying to match `!`
LL | (#![$inner:meta]) => ()
| ^
-error: aborting due to previous error
+error: aborting due to 1 previous error
diff --git a/tests/ui/parser/macro/macro-expand-to-field.rs b/tests/ui/parser/macro/macro-expand-to-field.rs
new file mode 100644
index 000000000..533511ecf
--- /dev/null
+++ b/tests/ui/parser/macro/macro-expand-to-field.rs
@@ -0,0 +1,79 @@
+// compile-flags: --crate-type=lib
+
+// https://github.com/rust-lang/rust/issues/113766
+
+macro_rules! field {
+ ($name:ident:$type:ty) => {
+ $name:$type
+ };
+}
+
+macro_rules! variant {
+ ($name:ident) => {
+ $name
+ }
+}
+
+struct Struct {
+ //~^ NOTE while parsing this struct
+ field!(bar:u128),
+ //~^ NOTE macros cannot expand to struct fields
+ //~| ERROR unexpected token: `!`
+ //~| NOTE unexpected token after this
+ a: u32,
+ b: u32,
+ field!(recovers:()),
+}
+
+enum EnumVariant {
+ variant!(whoops),
+ //~^ NOTE macros cannot expand to enum variants
+ //~| ERROR unexpected token: `!`
+ //~| NOTE unexpected token after this
+ U32,
+ F64,
+ variant!(recovers),
+ //~^ NOTE macros cannot expand to enum variants
+ //~| ERROR unexpected token: `!`
+ //~| NOTE unexpected token after this
+ Data { //~ NOTE while parsing this struct
+ field!(x:u32),
+ //~^ NOTE macros cannot expand to struct fields
+ //~| ERROR unexpected token: `!`
+ //~| NOTE unexpected token after this
+ }
+}
+
+enum EnumVariantField {
+ Named { //~ NOTE while parsing this struct
+ field!(oopsies:()),
+ //~^ NOTE macros cannot expand to struct fields
+ //~| ERROR unexpected token: `!`
+ //~| unexpected token after this
+ field!(oopsies2:()),
+ },
+}
+
+union Union {
+ //~^ NOTE while parsing this union
+ A: u32,
+ field!(oopsies:()),
+ //~^ NOTE macros cannot expand to union fields
+ //~| ERROR unexpected token: `!`
+ //~| NOTE unexpected token after this
+ B: u32,
+ field!(recovers:()),
+}
+
+// https://github.com/rust-lang/rust/issues/114636
+
+#[derive(Debug)]
+pub struct Lazy {
+ //~^ NOTE while parsing this struct
+ unreachable!()
+ //~^ NOTE macros cannot expand to struct fields
+ //~| ERROR unexpected token: `!`
+ //~| NOTE unexpected token after this
+}
+
+fn main() {}
diff --git a/tests/ui/parser/macro/macro-expand-to-field.stderr b/tests/ui/parser/macro/macro-expand-to-field.stderr
new file mode 100644
index 000000000..0bb718000
--- /dev/null
+++ b/tests/ui/parser/macro/macro-expand-to-field.stderr
@@ -0,0 +1,71 @@
+error: unexpected token: `!`
+ --> $DIR/macro-expand-to-field.rs:19:10
+ |
+LL | struct Struct {
+ | ------ while parsing this struct
+LL |
+LL | field!(bar:u128),
+ | ^ unexpected token after this
+ |
+ = note: macros cannot expand to struct fields
+
+error: unexpected token: `!`
+ --> $DIR/macro-expand-to-field.rs:29:12
+ |
+LL | variant!(whoops),
+ | ^ unexpected token after this
+ |
+ = note: macros cannot expand to enum variants
+
+error: unexpected token: `!`
+ --> $DIR/macro-expand-to-field.rs:35:12
+ |
+LL | variant!(recovers),
+ | ^ unexpected token after this
+ |
+ = note: macros cannot expand to enum variants
+
+error: unexpected token: `!`
+ --> $DIR/macro-expand-to-field.rs:40:14
+ |
+LL | Data {
+ | ---- while parsing this struct
+LL | field!(x:u32),
+ | ^ unexpected token after this
+ |
+ = note: macros cannot expand to struct fields
+
+error: unexpected token: `!`
+ --> $DIR/macro-expand-to-field.rs:49:14
+ |
+LL | Named {
+ | ----- while parsing this struct
+LL | field!(oopsies:()),
+ | ^ unexpected token after this
+ |
+ = note: macros cannot expand to struct fields
+
+error: unexpected token: `!`
+ --> $DIR/macro-expand-to-field.rs:60:10
+ |
+LL | union Union {
+ | ----- while parsing this union
+...
+LL | field!(oopsies:()),
+ | ^ unexpected token after this
+ |
+ = note: macros cannot expand to union fields
+
+error: unexpected token: `!`
+ --> $DIR/macro-expand-to-field.rs:73:16
+ |
+LL | pub struct Lazy {
+ | ---- while parsing this struct
+LL |
+LL | unreachable!()
+ | ^ unexpected token after this
+ |
+ = note: macros cannot expand to struct fields
+
+error: aborting due to 7 previous errors
+
diff --git a/tests/ui/parser/macro/macro-expand-to-match-arm.rs b/tests/ui/parser/macro/macro-expand-to-match-arm.rs
new file mode 100644
index 000000000..db38fa0d7
--- /dev/null
+++ b/tests/ui/parser/macro/macro-expand-to-match-arm.rs
@@ -0,0 +1,20 @@
+macro_rules! arm {
+ ($pattern:pat => $block:block) => {
+ $pattern => $block
+ //~^ ERROR macro expansion ignores token `=>` and any following
+ //~| NOTE the usage of `arm!` is likely invalid in pattern context
+ //~| NOTE macros cannot expand to match arms
+ };
+}
+
+fn main() {
+ let x = Some(1);
+ match x {
+ Some(1) => {},
+ arm!(None => {}),
+ //~^ NOTE caused by the macro expansion here
+ //~| ERROR `match` arm with no body
+ Some(2) => {},
+ _ => {},
+ };
+}
diff --git a/tests/ui/parser/macro/macro-expand-to-match-arm.stderr b/tests/ui/parser/macro/macro-expand-to-match-arm.stderr
new file mode 100644
index 000000000..e3e7ff89c
--- /dev/null
+++ b/tests/ui/parser/macro/macro-expand-to-match-arm.stderr
@@ -0,0 +1,20 @@
+error: macro expansion ignores token `=>` and any following
+ --> $DIR/macro-expand-to-match-arm.rs:3:18
+ |
+LL | $pattern => $block
+ | ^^
+...
+LL | arm!(None => {}),
+ | ---------------- caused by the macro expansion here
+ |
+ = note: the usage of `arm!` is likely invalid in pattern context
+ = note: macros cannot expand to match arms
+
+error: `match` arm with no body
+ --> $DIR/macro-expand-to-match-arm.rs:14:9
+ |
+LL | arm!(None => {}),
+ | ^^^^^^^^^^^^^^^^- help: add a body after the pattern: `=> todo!(),`
+
+error: aborting due to 2 previous errors
+
diff --git a/tests/ui/parser/macro/macro-repeat.stderr b/tests/ui/parser/macro/macro-repeat.stderr
index 63554b197..ade2bbf9b 100644
--- a/tests/ui/parser/macro/macro-repeat.stderr
+++ b/tests/ui/parser/macro/macro-repeat.stderr
@@ -9,6 +9,8 @@ error: variable 'v' is still repeating at this depth
|
LL | $v
| ^^
+ |
+ = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: aborting due to 2 previous errors