diff options
Diffstat (limited to '')
-rw-r--r-- | tests/ui/parser/macro/macro-expand-to-field.rs | 70 |
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 +} |