Nonnull::dangling_with_align(usize)?

In my "allocator"/"storage" for my untyped vector, I use NonNull::dangling for unallocted heap pointer any_vec/heap.rs at main · tower120/any_vec · GitHub .

The problem is - allocator work with Layout, and without concrete type (very much like std::alloc::Allocator). Memory represented as heap with NonNull pointer to it. So when I call NonNull::dangling - it create pointer with 1 byte align (u8 size). When I create empty slice of concrete type from it - I have message from MIRI that pointer align is mismatch with concrete type. Which is technically true.

So, if NonNull::dangling could be constructed with align or Layout - that would solve my problem.

Or maybe some other way to create pointer to uninitialized memory with specific Layout.

P.S. I can construct pointer with address = Layout.align(), but I have filling that there is also some black compiler magic for NonNull::dangling.

Layout::dangling

This is more a question about using Rust, so is likely a better fit for the users forum.

It is defined as allowed to create an allocation to a ZST via align as *mut ZST.

For more information see invalid in std::ptr - Rust

Oh, so there is such thing (its just unstable) - I didn't know about Layout::dangling. I was somehow sure there isn't.

I think this can be "closed" then.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.