summaryrefslogtreecommitdiffstats
path: root/tests/ui/parser/macro/macro-expand-to-field.rs
blob: 155872f7a5d791adf9591f9f4ac061740b97cd85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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
}