summaryrefslogtreecommitdiffstats
path: root/tests/ui/parser/macro/macro-expand-to-field.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
commitd1b2d29528b7794b41e66fc2136e395a02f8529b (patch)
treea4a17504b260206dec3cf55b2dca82929a348ac2 /tests/ui/parser/macro/macro-expand-to-field.rs
parentReleasing progress-linux version 1.72.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.tar.xz
rustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.zip
Merging upstream version 1.73.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/parser/macro/macro-expand-to-field.rs')
-rw-r--r--tests/ui/parser/macro/macro-expand-to-field.rs70
1 files changed, 70 insertions, 0 deletions
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..155872f7a
--- /dev/null
+++ b/tests/ui/parser/macro/macro-expand-to-field.rs
@@ -0,0 +1,70 @@
+// compile-flags: --crate-type=lib
+
+macro_rules! field {
+ ($name:ident:$type:ty) => {
+ $name:$type
+ };
+}
+
+macro_rules! variant {
+ ($name:ident) => {
+ $name
+ }
+}
+
+struct 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:()), //~ NOTE macros cannot expand to struct fields
+ //~^ ERROR unexpected token: `!`
+ //~^^ NOTE unexpected token after this
+}
+
+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 {
+ field!(x:u32),
+ //~^ NOTE macros cannot expand to struct fields
+ //~| ERROR unexpected token: `!`
+ //~| NOTE unexpected token after this
+ }
+}
+
+enum EnumVariantField {
+ Named {
+ field!(oopsies:()),
+ //~^ NOTE macros cannot expand to struct fields
+ //~| ERROR unexpected token: `!`
+ //~| unexpected token after this
+ field!(oopsies2:()),
+ //~^ NOTE macros cannot expand to struct fields
+ //~| ERROR unexpected token: `!`
+ //~| unexpected token after this
+ },
+}
+
+union Union {
+ A: u32,
+ field!(oopsies:()),
+ //~^ NOTE macros cannot expand to union fields
+ //~| ERROR unexpected token: `!`
+ //~| unexpected token after this
+ B: u32,
+ field!(recovers:()),
+ //~^ NOTE macros cannot expand to union fields
+ //~| ERROR unexpected token: `!`
+ //~| unexpected token after this
+}