2024-12-18 22:05:27 +01:00
|
|
|
// Checks that the #[unsafe(naked)] attribute can be placed on function definitions only.
|
2020-11-24 00:00:00 +00:00
|
|
|
//
|
2021-04-13 00:00:00 +00:00
|
|
|
//@ needs-asm-support
|
2025-03-29 17:30:11 +01:00
|
|
|
#![unsafe(naked)] //~ ERROR should be applied to a function definition
|
2020-11-24 00:00:00 +00:00
|
|
|
|
2024-09-05 13:45:26 +02:00
|
|
|
use std::arch::naked_asm;
|
2021-12-10 00:15:33 +00:00
|
|
|
|
2020-11-24 00:00:00 +00:00
|
|
|
extern "C" {
|
2025-03-29 17:30:11 +01:00
|
|
|
#[unsafe(naked)] //~ ERROR should be applied to a function definition
|
2020-11-24 00:00:00 +00:00
|
|
|
fn f();
|
|
|
|
}
|
|
|
|
|
2025-03-29 17:30:11 +01:00
|
|
|
#[unsafe(naked)] //~ ERROR should be applied to a function definition
|
2020-11-24 00:00:00 +00:00
|
|
|
#[repr(C)]
|
|
|
|
struct S {
|
2024-12-18 22:05:27 +01:00
|
|
|
#[unsafe(naked)] //~ ERROR should be applied to a function definition
|
2020-11-24 00:00:00 +00:00
|
|
|
a: u32,
|
|
|
|
b: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
trait Invoke {
|
2025-03-29 17:30:11 +01:00
|
|
|
#[unsafe(naked)] //~ ERROR should be applied to a function definition
|
2020-11-24 00:00:00 +00:00
|
|
|
extern "C" fn invoke(&self);
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Invoke for S {
|
2025-03-29 17:30:11 +01:00
|
|
|
#[unsafe(naked)]
|
2020-11-24 00:00:00 +00:00
|
|
|
extern "C" fn invoke(&self) {
|
2025-03-29 17:30:11 +01:00
|
|
|
naked_asm!("")
|
2020-11-24 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-03-29 17:30:11 +01:00
|
|
|
#[unsafe(naked)]
|
2020-11-24 00:00:00 +00:00
|
|
|
extern "C" fn ok() {
|
2025-03-29 17:30:11 +01:00
|
|
|
naked_asm!("")
|
2020-11-24 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl S {
|
2025-03-29 17:30:11 +01:00
|
|
|
#[unsafe(naked)]
|
2020-11-24 00:00:00 +00:00
|
|
|
extern "C" fn g() {
|
2025-03-29 17:30:11 +01:00
|
|
|
naked_asm!("")
|
2020-11-24 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2025-03-29 17:30:11 +01:00
|
|
|
#[unsafe(naked)]
|
2020-11-24 00:00:00 +00:00
|
|
|
extern "C" fn h(&self) {
|
2025-03-29 17:30:11 +01:00
|
|
|
naked_asm!("")
|
2020-11-24 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2025-03-29 17:30:11 +01:00
|
|
|
#[unsafe(naked)] //~ ERROR should be applied to a function definition
|
2024-09-05 13:45:26 +02:00
|
|
|
|| {};
|
2020-11-24 00:00:00 +00:00
|
|
|
}
|