Skip to content

Commit 2fde064

Browse files
committed
Mention that asm! is unsafe
1 parent 52ffdc0 commit 2fde064

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

‎src/inline-assembly.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,6 +1567,9 @@ extern "sysv64-unwind" fn may_panic() {
15671567
r[asm.validity]
15681568
### Correctness and validity
15691569

1570+
r[asm.validity.unsafe]
1571+
Using `asm!` requires `unsafe`, and the programmer is responsible for ensuring that the assembly code is correct and valid.
1572+
15701573
r[asm.validity.necessary-but-not-sufficient]
15711574
In addition to all of the previous rules, the string argument to `asm!` must ultimately become---after all other arguments are evaluated, formatting is performed, and operands are translated---assembly that is both syntactically correct and semantically valid for the target architecture. The formatting rules allow the compiler to generate assembly with correct syntax. Rules concerning operands permit valid translation of Rust operands into and out of the assembly code. Adherence to these rules is necessary, but not sufficient, for the final expanded assembly to be both correct and valid. For instance:
15721575

‎src/unsafety.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ r[safety.unsafe-extern]
3131
r[safety.unsafe-attribute]
3232
- Applying an [unsafe attribute] to an item.
3333

34+
r[safety.unsafe-asm]
35+
- Using the [`asm!`] macro.
36+
3437
[^extern-2024]: Prior to the 2024 edition, extern blocks were allowed to be declared without `unsafe`.
3538

3639
[`extern`]: items/external-blocks.md
@@ -40,3 +43,4 @@ r[safety.unsafe-attribute]
4043
[raw pointer]: types/pointer.md
4144
[unsafe trait]: items/traits.md#unsafe-traits
4245
[unsafe attribute]: attributes.md
46+
[`asm!`]: inline-assembly.md

0 commit comments

Comments
 (0)