Rust's SIMD is finally safe — and the trick is a zero-sized token

Safe SIMD in Rust, even on the inside

Rust's SIMD abstractions hid vast amounts of unsafe code beneath their surface, occasionally leading to bugs. Sergey "Shnatsel" Davidoff explains how an unforgeable zero-sized token, obtained only after a runtime CPU feature check, lets you call AVX2 intrinsics without unsafe. A macro encapsulates the one unsafe block, and generics over instruction-set levels give you a + b with automatic dispatch. The catch: function call overhead means you must inline or annotate with #[target_feature].

Inside, they're still full of unsafe. It wasn't gone, just hidden. Vast quantities of it lurking just beneath the surface, getting screwed up occasionally.

More from this day

2026-10-11