Weird behavior in unsafe rust
⚓ Rust 📅 2025-10-27 👤 surdeus 👁️ 3I've been writing code for stack allocation, but with a stack on the heap (actually multiple stacks, but that's not entirely relevant). I've implemented a few easy data structures for it, but now I want to implement b-tree maps. However, it's running into weird UB that I can't find the source of.
I've made a minimal example that uses normal heap allocation, lacks a bunch of lifetime stuff and PhantomDatas, and isn't fully functional, but results in the very strange errors and the compiler emitting a UD2 instruction. Other errors include add/subtract with overflow in random places and index out of bounds: the len is 11 but the index is 65530 in insert_kv_unchecked (which is only possible if it takes the wrong branch).
Note that I am currently on rust 1.89 on gentoo amd64.
2 posts - 2 participants
🏷️ Rust_feed