Skip to content

Implement a `trap()` function

Compare
Choose a tag to compare
@Techcable Techcable released this 20 Jun 01:26
· 9 commits to master since this release
ba73973

The trap() function issues an illegal instruction on supported architectures, falling back to calling abort() elsewhere. It is semantically equivalent to the llvm.trap and __builtin_abort() intrinsics.

On some architectures, issuing an illegal instruction is cheaper than calling an abort function.

The trap function can be used to implement the abort() function by enabling the trap-via-abort feature. This feature does nothing if the architecture is unsupported.

Currently supported architectures for trap:

  • x86_64
  • i686 (x86)
  • aarch64
  • arm
  • wasm32
  • wasm64

On nightly, the trap function wraps the core::intrisnics::abort() function.

Additional fixes:

  • Use doc(cfg(...)) to document feature requirements
  • Properly configure feature flags for docs.rs
  • Drop rustversion dependency in favor of detection in build.rs script.