about summary refs log tree commit diff
path: root/tests/ui/macros/macro-rules-derive-error.rs
blob: 3ef0236c5283cb187c170489c398037c15744f46 (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
#![feature(macro_derive)]

macro_rules! MyDerive {
    derive() { $($body:tt)* } => {
        compile_error!(concat!("MyDerive: ", stringify!($($body)*)));
    };
    //~^^ ERROR: MyDerive
}

macro_rules! fn_only {
//~^ NOTE: `fn_only` exists, but has no `derive` rules
//~| NOTE: `fn_only` exists, but has no `derive` rules
    {} => {}
}

//~v NOTE: `DeriveOnly` exists, but has no rules for function-like invocation
macro_rules! DeriveOnly {
    derive() {} => {}
}

fn main() {
    //~v NOTE: in this expansion of #[derive(MyDerive)]
    #[derive(MyDerive)]
    struct S1;

    //~vv ERROR: cannot find macro `MyDerive` in this scope
    //~| NOTE: `MyDerive` is in scope, but it is a derive
    MyDerive!(arg);

    #[derive(fn_only)]
    struct S2;
    //~^^ ERROR: cannot find derive macro `fn_only` in this scope
    //~| ERROR: cannot find derive macro `fn_only` in this scope
    //~| NOTE: duplicate diagnostic emitted

    DeriveOnly!(); //~ ERROR: cannot find macro `DeriveOnly` in this scope
}

#[derive(ForwardReferencedDerive)]
struct S;
//~^^ ERROR: cannot find derive macro `ForwardReferencedDerive` in this scope
//~| NOTE: consider moving the definition of `ForwardReferencedDerive` before this call
//~| ERROR: cannot find derive macro `ForwardReferencedDerive` in this scope
//~| NOTE: consider moving the definition of `ForwardReferencedDerive` before this call
//~| NOTE: duplicate diagnostic emitted

macro_rules! ForwardReferencedDerive {
//~^ NOTE: a macro with the same name exists, but it appears later
//~| NOTE: a macro with the same name exists, but it appears later
    derive() {} => {}
}