about summary refs log tree commit diff
path: root/tests/ui/macros/macro-rules-attr-error.rs
blob: 60290b883cb8617d11d979a3a09f4041778bc371 (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
71
#![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() {} => {}
}

macro_rules! attr_with_safety {
    unsafe attr() { struct RequiresUnsafe; } => {};
    attr() { struct SafeInvocation; } => {};
}

#[attr_with_safety]
struct SafeInvocation;

//~v ERROR: unnecessary `unsafe` on safe attribute invocation
#[unsafe(attr_with_safety)]
struct SafeInvocation;

//~v ERROR: unsafe attribute invocation requires `unsafe`
#[attr_with_safety]
struct RequiresUnsafe;

#[unsafe(attr_with_safety)]
struct RequiresUnsafe;