summaryrefslogtreecommitdiffstats
path: root/src/test/ui/asm/naked-functions-unused.rs
blob: 044a0e5b9408989c3df795c31155fbfd0aa47382 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// revisions: x86_64 aarch64
// needs-asm-support
//[x86_64] only-x86_64
//[aarch64] only-aarch64
#![deny(unused)]
#![feature(naked_functions)]
#![crate_type = "lib"]

pub trait Trait {
    extern "C" fn trait_associated(a: usize, b: usize) -> usize;
    extern "C" fn trait_method(&self, a: usize, b: usize) -> usize;
}

pub mod normal {
    use std::arch::asm;

    pub extern "C" fn function(a: usize, b: usize) -> usize {
        //~^ ERROR unused variable: `a`
        //~| ERROR unused variable: `b`
        unsafe { asm!("", options(noreturn)); }
    }

    pub struct Normal;

    impl Normal {
        pub extern "C" fn associated(a: usize, b: usize) -> usize {
            //~^ ERROR unused variable: `a`
            //~| ERROR unused variable: `b`
            unsafe { asm!("", options(noreturn)); }
        }

        pub extern "C" fn method(&self, a: usize, b: usize) -> usize {
            //~^ ERROR unused variable: `a`
            //~| ERROR unused variable: `b`
            unsafe { asm!("", options(noreturn)); }
        }
    }

    impl super::Trait for Normal {
        extern "C" fn trait_associated(a: usize, b: usize) -> usize {
            //~^ ERROR unused variable: `a`
            //~| ERROR unused variable: `b`
            unsafe { asm!("", options(noreturn)); }
        }

        extern "C" fn trait_method(&self, a: usize, b: usize) -> usize {
            //~^ ERROR unused variable: `a`
            //~| ERROR unused variable: `b`
            unsafe { asm!("", options(noreturn)); }
        }
    }
}

pub mod naked {
    use std::arch::asm;

    #[naked]
    pub extern "C" fn function(a: usize, b: usize) -> usize {
        unsafe { asm!("", options(noreturn)); }
    }

    pub struct Naked;

    impl Naked {
        #[naked]
        pub extern "C" fn associated(a: usize, b: usize) -> usize {
            unsafe { asm!("", options(noreturn)); }
        }

        #[naked]
        pub extern "C" fn method(&self, a: usize, b: usize) -> usize {
            unsafe { asm!("", options(noreturn)); }
        }
    }

    impl super::Trait for Naked {
        #[naked]
        extern "C" fn trait_associated(a: usize, b: usize) -> usize {
            unsafe { asm!("", options(noreturn)); }
        }

        #[naked]
        extern "C" fn trait_method(&self, a: usize, b: usize) -> usize {
            unsafe { asm!("", options(noreturn)); }
        }
    }
}