rust-lang / rust-lang/rust

`std::arch::wasm::unreachable()` is stable but does not compile

Open
#133,015 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics A-stability D-imprecise-spans D-papercut O-wasm
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried to build this code with cargo build --target=wasm32-unknown-unknown:

pub fn force_wasm_trap() {
    std::arch::wasm::unreachable();
}

I expected to see this happen: compile succeeds, generates a function containing the wasm "unreachable" instruction, which is what the documentation says it does.

Instead, this happened:

error[E0658]: use of unstable library feature 'simd_wasm64'
 --> src/lib.rs:2:5
  |
2 |     std::arch::wasm::unreachable();
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #90599 <https://github.com/rust-lang/rust/issues/90599> for more information

For more information about this error, try `rustc --explain E0658`.

I don't understand what happened: the documentation says this has been stable since rust 1.37.0, and I don't think there's any reason why the webassembly "unreachable" instruction would be tied to the unstable "simd_wasm64" feature.

I also tried with and without #[no_std] and using both core::arch and std::arch: all fail the same way.

Meta

rustc --version --verbose:

rustc 1.82.0 (f6e511eec 2024-10-15)
binary: rustc
commit-hash: f6e511eec7342f59a25f7c0534f1dbea00d01b14
commit-date: 2024-10-15
host: x86_64-unknown-linux-gnu
release: 1.82.0
LLVM version: 19.1.1

The same error happens with 1.83.0-beta.5 and nightly-2024-11-12.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the example with cargo build --target=wasm32-unknown-unknown and inspect the std::arch::wasm::unreachable entry point alongside issue #90599. Done means the documented stable API compiles on the wasm target and generates the WebAssembly unreachable instruction without requiring simd_wasm64.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, wasm
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.