Skip to content

False positive missing unsafe on WASM32 intrinsics #20640

@eternal-flame-AD

Description

@eternal-flame-AD

Looks similar to #5412 but doesn't look like it is the same issue (no proc_macros involved).

rust-analyzer version: rust-analyzer version: 0.4.2608-standalone

rustc version: (eg. output of rustc -V): Reproducible on:

  • rustc 1.91.0-nightly (9c27f27 2025-09-08)
  • rustc 1.89.0 (29483883e 2025-08-04)

editor or extension: VSCode (reproducible on Cursor as well) 0.4.2608

relevant settings: (eg. client settings, or environment variables like CARGO, RUSTC, RUSTUP_HOME or CARGO_HOME)

{
    "rust-analyzer.cargo.target": "wasm32-unknown-unknown"
}

code snippet to reproduce:

use core::arch::wasm32::*;

fn get_hello() -> v128 {
    u32x4(
        u32::from_ne_bytes(*b"hell"),
        u32::from_ne_bytes(*b"o,wo"),
        u32::from_ne_bytes(*b"rld!"),
        0,
    )
}

fn main() {
    let mut out = [0u8; 16];
    unsafe {
        let hello = get_hello();
        v128_store(out.as_mut_ptr().cast(), hello);
    };
    println!("{:?}", String::from_utf8_lossy(&out));
}

Output:

[{
	"resource": "rs-play/src/main.rs",
	"owner": "rust-analyzer",
	"code": {
		"value": "E0133",
		"target": {
			"$mid": 1,
			"path": "/stable/error_codes/E0133.html",
			"scheme": "https",
			"authority": "doc.rust-lang.org"
		}
	},
	"severity": 8,
	"message": "call to unsafe function is unsafe and requires an unsafe function or block",
	"source": "rust-analyzer",
	"startLineNumber": 4,
	"startColumn": 5,
	"endLineNumber": 9,
	"endColumn": 6,
	"modelVersionId": 5
}]

But it builds and runs, on Rustdoc this function is not marked unsafe:

> cargo run --release --target wasm32-wasip1 
     Running `wasmtime target/wasm32-wasip1/release/rs-play.wasm`
"hello,world!\0\0\0\0"

I tried combinations of -Ctarget-feature=+simd128 or no target-features, wasm32-unknown-unknown and wasm32-wasip1, the error still persists.

Metadata

Metadata

Labels

C-bugCategory: bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions