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

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

//~v NOTE: `fn_only` exists, but has no `attr` rules
macro_rules! fn_only {
    {} => {}
}

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

fn main() {
    //~v NOTE: in this expansion of #[local_attr]
    #[local_attr]
    struct S;

    //~vv ERROR: cannot find macro `local_attr` in this scope
    //~| NOTE: `local_attr` is in scope, but it is an attribute
    local_attr!(arg);

    //~v ERROR: cannot find attribute `fn_only` in this scope
    #[fn_only]
    struct S;

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

//~vv ERROR: cannot find attribute `forward_referenced_attr` in this scope
//~| NOTE: consider moving the definition of `forward_referenced_attr` before this call
#[forward_referenced_attr]
struct S;

//~v NOTE: a macro with the same name exists, but it appears later
macro_rules! forward_referenced_attr {
    attr() {} => {}
}

//~vv ERROR: cannot find attribute `cyclic_attr` in this scope
//~| NOTE: consider moving the definition of `cyclic_attr` before this call
#[cyclic_attr]
//~v NOTE: a macro with the same name exists, but it appears later
macro_rules! cyclic_attr {
    attr() {} => {}
}