about summary refs log tree commit diff
path: root/tests/ui
diff options
context:
space:
mode:
authorCatherine Flores <catherine.3.flores@gmail.com>2023-08-02 23:59:30 +0000
committerCatherine Flores <catherine.3.flores@gmail.com>2023-08-02 23:59:30 +0000
commitbbd69e4a4c27f2407326a71a4eb37de694a72b87 (patch)
treee7093294dd1e1a90b486942c3aa21ee0d6dd5775 /tests/ui
parentdece622ee48d9744d6e64891a734e8fd25eac903 (diff)
downloadrust-bbd69e4a4c27f2407326a71a4eb37de694a72b87.tar.gz
rust-bbd69e4a4c27f2407326a71a4eb37de694a72b87.zip
Add test for enum with fields
Diffstat (limited to 'tests/ui')
-rw-r--r--tests/ui/parser/macro/macro-expand-to-field.rs57
-rw-r--r--tests/ui/parser/macro/macro-expand-to-field.stderr22
-rw-r--r--tests/ui/parser/macro/macro-expand-to-match-arm.rs5
3 files changed, 53 insertions, 31 deletions
diff --git a/tests/ui/parser/macro/macro-expand-to-field.rs b/tests/ui/parser/macro/macro-expand-to-field.rs
index fd1d408e726..155872f7a5d 100644
--- a/tests/ui/parser/macro/macro-expand-to-field.rs
+++ b/tests/ui/parser/macro/macro-expand-to-field.rs
@@ -1,4 +1,4 @@
-#![no_main]
+// compile-flags: --crate-type=lib
 
 macro_rules! field {
     ($name:ident:$type:ty) => {
@@ -13,9 +13,10 @@ macro_rules! variant {
 }
 
 struct Struct {
-    field!(bar:u128), //~ NOTE macros cannot expand to struct fields
-    //~^ ERROR unexpected token: `!`
-    //~^^ NOTE unexpected token after this
+    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
@@ -24,34 +25,46 @@ struct Struct {
 }
 
 enum EnumVariant {
-    variant!(whoops), //~ NOTE macros cannot expand to enum variants
-    //~^ ERROR unexpected token: `!`
-    //~^^ NOTE unexpected token after this
+    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
+    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
+        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
+    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
+    field!(recovers:()),
+    //~^ NOTE macros cannot expand to union fields
+    //~| ERROR unexpected token: `!`
+    //~| unexpected token after this
 }
diff --git a/tests/ui/parser/macro/macro-expand-to-field.stderr b/tests/ui/parser/macro/macro-expand-to-field.stderr
index 108b68b481f..adcd032f5c0 100644
--- a/tests/ui/parser/macro/macro-expand-to-field.stderr
+++ b/tests/ui/parser/macro/macro-expand-to-field.stderr
@@ -7,7 +7,7 @@ LL |     field!(bar:u128),
    = note: macros cannot expand to struct fields
 
 error: unexpected token: `!`
-  --> $DIR/macro-expand-to-field.rs:21:10
+  --> $DIR/macro-expand-to-field.rs:22:10
    |
 LL |     field!(recovers:()),
    |          ^ unexpected token after this
@@ -15,7 +15,7 @@ LL |     field!(recovers:()),
    = note: macros cannot expand to struct fields
 
 error: unexpected token: `!`
-  --> $DIR/macro-expand-to-field.rs:27:12
+  --> $DIR/macro-expand-to-field.rs:28:12
    |
 LL |     variant!(whoops),
    |            ^ unexpected token after this
@@ -23,7 +23,7 @@ LL |     variant!(whoops),
    = note: macros cannot expand to enum variants
 
 error: unexpected token: `!`
-  --> $DIR/macro-expand-to-field.rs:32:12
+  --> $DIR/macro-expand-to-field.rs:34:12
    |
 LL |     variant!(recovers),
    |            ^ unexpected token after this
@@ -33,13 +33,21 @@ LL |     variant!(recovers),
 error: unexpected token: `!`
   --> $DIR/macro-expand-to-field.rs:39:14
    |
+LL |         field!(x:u32),
+   |              ^ unexpected token after this
+   |
+   = note: macros cannot expand to struct fields
+
+error: unexpected token: `!`
+  --> $DIR/macro-expand-to-field.rs:48:14
+   |
 LL |         field!(oopsies:()),
    |              ^ unexpected token after this
    |
    = note: macros cannot expand to struct fields
 
 error: unexpected token: `!`
-  --> $DIR/macro-expand-to-field.rs:42:14
+  --> $DIR/macro-expand-to-field.rs:52:14
    |
 LL |         field!(oopsies2:()),
    |              ^ unexpected token after this
@@ -47,7 +55,7 @@ LL |         field!(oopsies2:()),
    = note: macros cannot expand to struct fields
 
 error: unexpected token: `!`
-  --> $DIR/macro-expand-to-field.rs:50:10
+  --> $DIR/macro-expand-to-field.rs:61:10
    |
 LL |     field!(oopsies:()),
    |          ^ unexpected token after this
@@ -55,12 +63,12 @@ LL |     field!(oopsies:()),
    = note: macros cannot expand to union fields
 
 error: unexpected token: `!`
-  --> $DIR/macro-expand-to-field.rs:54:10
+  --> $DIR/macro-expand-to-field.rs:66:10
    |
 LL |     field!(recovers:()),
    |          ^ unexpected token after this
    |
    = note: macros cannot expand to union fields
 
-error: aborting due to 8 previous errors
+error: aborting due to 9 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
index c176e8bbd9d..39d1d065ed9 100644
--- a/tests/ui/parser/macro/macro-expand-to-match-arm.rs
+++ b/tests/ui/parser/macro/macro-expand-to-match-arm.rs
@@ -8,8 +8,9 @@ fn main() {
     let x = Some(1);
     match x {
         Some(1) => {},
-        arm!(None => {}), //~ NOTE macros cannot expand to match arms
-        //~^ ERROR unexpected `,` in pattern
+        arm!(None => {}),
+        //~^ NOTE macros cannot expand to match arms
+        //~| ERROR unexpected `,` in pattern
         // doesn't recover
         Some(2) => {},
         _ => {},