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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

80 lines
1.9 KiB
Rust
Raw Normal View History

2023-08-02 18:59:30 -05:00
// 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
}
}
2023-07-24 12:05:10 -05:00
struct Struct {
//~^ NOTE while parsing this 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:()),
}
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 { //~ NOTE while parsing this struct
2023-08-02 18:59:30 -05:00
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 { //~ NOTE while parsing this struct
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:()),
2023-07-24 12:05:10 -05:00
},
}
union Union {
//~^ NOTE while parsing this union
2023-07-24 12:05:10 -05:00
A: u32,
2023-08-02 18:59:30 -05:00
field!(oopsies:()),
//~^ NOTE macros cannot expand to union fields
//~| ERROR unexpected token: `!`
//~| NOTE unexpected token after this
2023-07-24 12:05:10 -05:00
B: u32,
2023-08-02 18:59:30 -05:00
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
2023-08-02 18:59:30 -05:00
//~| ERROR unexpected token: `!`
//~| NOTE unexpected token after this
}
fn main() {}