rust/tests/ui/parser/macro/macro-expand-to-field.rs

71 lines
1.7 KiB
Rust
Raw Normal View History

2023-08-02 18:59:30 -05:00
// compile-flags: --crate-type=lib
macro_rules! field {
($name:ident:$type:ty) => {
$name:$type
};
}
macro_rules! variant {
($name:ident) => {
$name
}
}
2023-07-24 12:05:10 -05:00
struct Struct {
2023-08-02 18:59:30 -05:00
field!(bar:u128),
//~^ NOTE macros cannot expand to struct fields
//~| ERROR unexpected token: `!`
//~| NOTE unexpected token after this
2023-07-24 12:05:10 -05:00
a: u32,
b: u32,
field!(recovers:()), //~ NOTE macros cannot expand to struct fields
//~^ ERROR unexpected token: `!`
//~^^ NOTE unexpected token after this
}
2023-07-24 12:05:10 -05:00
enum EnumVariant {
2023-08-02 18:59:30 -05:00
variant!(whoops),
//~^ NOTE macros cannot expand to enum variants
//~| ERROR unexpected token: `!`
//~| NOTE unexpected token after this
2023-07-24 12:05:10 -05:00
U32,
F64,
2023-08-02 18:59:30 -05:00
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
}
2023-07-24 12:05:10 -05:00
}
enum EnumVariantField {
Named {
2023-08-02 18:59:30 -05:00
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
2023-07-24 12:05:10 -05:00
},
}
union Union {
A: u32,
2023-08-02 18:59:30 -05:00
field!(oopsies:()),
//~^ NOTE macros cannot expand to union fields
//~| ERROR unexpected token: `!`
//~| unexpected token after this
2023-07-24 12:05:10 -05:00
B: u32,
2023-08-02 18:59:30 -05:00
field!(recovers:()),
//~^ NOTE macros cannot expand to union fields
//~| ERROR unexpected token: `!`
//~| unexpected token after this
}