rust/tests/ui/asm/naked-invalid-attr.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

54 lines
1 KiB
Rust
Raw Normal View History

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