unsafe(#[attribute]) not working
Open
Nobody has claimed this yet.
A-attributes
A-diagnostics
A-macros
A-proc-macros
D-invalid-suggestion
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
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>
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the report from crates/syscalls/src/lib.rs with the provided rustc 1.92.0-nightly version, first comparing the #[syscalls] and unsafe(#[syscalls]) forms. Trace how the compiler handles unsafe attributes expanded by the attribute macro, then identify the relevant regression-test location. Done means the supported syntax is accepted or the diagnostic clearly explains the valid form, with coverage for this example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 43/100