Skip to content

Commit c57a8f9

Browse files
matkladAmanieu
authored andcommitted
mark core::arch::wasm32::unreachable as safe
This intrinsic doesn't have any preconditions and is always safe to call, so it can be safe. This function is already stable, but dropping `unsafe` is a backwards compatible change. Note tha we already have a precedent for wasm intrinsics being safe -- wasm simd is safe. It is relatively practically important to mark this safe -- wasm32::unreachable is directly useful in practice as more codesize efficient `panic!()`.
1 parent 62d5e7e commit c57a8f9

File tree

1 file changed

+7
-2
lines changed
  • crates/core_arch/src/wasm32

1 file changed

+7
-2
lines changed

crates/core_arch/src/wasm32/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@ pub use self::simd128::*;
1212
mod memory;
1313
pub use self::memory::*;
1414

15-
/// Generates the trap instruction `UNREACHABLE`
15+
/// Generates the [`unreachable`] instruction, which causes an unconditional [trap].
16+
///
17+
/// This function is safe to call and immediately aborts the execution.
18+
///
19+
/// [`unreachable`]: https://webassembly.github.io/spec/core/syntax/instructions.html#syntax-instr-control
20+
/// [trap]: https://webassembly.github.io/spec/core/intro/overview.html#trap
1621
#[cfg_attr(test, assert_instr(unreachable))]
1722
#[inline]
1823
#[stable(feature = "unreachable_wasm32", since = "1.37.0")]
19-
pub unsafe fn unreachable() -> ! {
24+
pub fn unreachable() -> ! {
2025
crate::intrinsics::abort()
2126
}

0 commit comments

Comments
 (0)