about summary refs log tree commit diff
path: root/tests/ui/asm/naked-invalid-attr.rs
blob: c9e0949abfb1efe353c99eb65763d85e7bd55c75 (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
// Checks that the #[unsafe(naked)] attribute can be placed on function definitions only.
//
//@ needs-asm-support
#![unsafe(naked)] //~ ERROR attribute cannot be used on

use std::arch::naked_asm;

extern "C" {
    #[unsafe(naked)] //~ ERROR attribute cannot be used on
    fn f();
}

#[unsafe(naked)] //~ ERROR attribute cannot be used on
#[repr(C)]
struct S {
    #[unsafe(naked)] //~ ERROR attribute cannot be used on
    a: u32,
    b: u32,
}

trait Invoke {
    #[unsafe(naked)] //~ ERROR attribute cannot be used on
    extern "C" fn invoke(&self);
}

impl Invoke for S {
    #[unsafe(naked)]
    extern "C" fn invoke(&self) {
        naked_asm!("")
    }
}

#[unsafe(naked)]
extern "C" fn ok() {
    naked_asm!("")
}

impl S {
    #[unsafe(naked)]
    extern "C" fn g() {
        naked_asm!("")
    }

    #[unsafe(naked)]
    extern "C" fn h(&self) {
        naked_asm!("")
    }
}

fn main() {
    #[unsafe(naked)] //~ ERROR attribute cannot be used on
    || {};
}

// Check that the path of an attribute without a name is printed correctly (issue #140082)
#[::a]
//~^ ERROR attribute incompatible with `#[unsafe(naked)]`
//~| ERROR failed to resolve: use of unresolved module or unlinked crate `a`
#[unsafe(naked)]
extern "C" fn issue_140082() {
    naked_asm!("")
}