Skip to content

unsafe(#[attribute]) not working #146840

@kjughx

Description

@kjughx

I have this code

#[syscalls]
extern "C" {
    pub fn exit(code: i32) -> usize;
}

which fails to compile:

error: unsafe attribute used without unsafe
 --> crates/syscalls/src/lib.rs:9:1
  |
9 | #[syscalls]
  | ^^^^^^^^^^^ usage of unsafe attribute
  |
  = note: this error originates in the attribute macro `syscalls` (in Nightly builds, run with -Z macro-backtrace for more info)
help: wrap the attribute in `unsafe(...)`
  |
9 | unsafe(#[syscalls])
  | +++++++           +

so I try what it says:

unsafe(#[syscalls])
extern "C" {
    pub fn exit(code: i32) -> usize;
}

and get another compilation error:

error: expected item, found keyword `unsafe`
 --> crates/syscalls/src/lib.rs:9:1
  |
9 | unsafe(#[syscalls])
  | ^^^^^^ expected item

Meta

rustc --version --verbose:

rustc 1.92.0-nightly (dd7fda570 2025-09-20)
binary: rustc
commit-hash: dd7fda570040e8a736f7d8bc28ddd1b444aabc82
commit-date: 2025-09-20
host: x86_64-unknown-linux-gnu
release: 1.92.0-nightly
LLVM version: 21.1.1
Backtrace

<backtrace>

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-attributesArea: Attributes (`#[…]`, `#![…]`)A-diagnosticsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-proc-macrosArea: Procedural macrosD-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions