impl AnyBitPattern for [MaybeUninit<T: AnyBitPattern>; N]#317
impl AnyBitPattern for [MaybeUninit<T: AnyBitPattern>; N]#317fu5ha merged 1 commit intoLokathor:mainfrom
AnyBitPattern for [MaybeUninit<T: AnyBitPattern>; N]#317Conversation
|
@fu5ha ping! will you be available to review this any time soon? |
|
I think so! Setting a remider |
fu5ha
left a comment
There was a problem hiding this comment.
This makes sense to me, but I think we could actually broaden this to instead be
#[cfg(feature = "min_const_generics")]
#[cfg_attr(
feature = "nightly_docs",
doc(cfg(
feature = "min_const_generics"
))
)]
unsafe impl<T, const N: usize> AnyBitPattern for [T; N] where
T: AnyBitPattern
{
}Which would then get [MaybeUninit<T>; N] for free.
Also this is making me think that we could broaden the existing impl<T> AnyBitPattern for MaybeUninit<T> where T: AnyBitPattern to drop the T: AnyBitPattern bound. MaybeUninit<T> is in general AnyBitPattern no matter what is the inner T, unless I'm missing something 🤔
This would conflict with the existing In a future (major) version of
This has possible issues with interior mutability. In particular, if |
|
I think this implementation is acceptable for the current state of the language specifications regarding soundness. I'm not exactly opposed to expanding the impl, but the reason I made this PR was that the implementation utilized existing ("known-good") soundness, and did not require any new soundness rules to be evaluated. |
Ah right, I was afraid of that. I guess that's why these blanket impls didn't already exist in the first place. OK, well, since we've thought about the more general options I think it makes sense to still get this minimal version in now. It doesn't exclude the possibility of making it broader in the future. |
|
Can put this on the list for a patch release when you get the time @Lokathor |
|
released in 1.24 |
Provides the following implementation:
Which allows arrays of
MaybeUninit<T: AnyBitPattern>to be treated asAnyBitPattern. For instance, the following struct is not currently possible via the safer derive macro forAnyBitPattern:Which results in the following error on the struct's tuple field:
... which complicates my current use case, of trying to safely allocate a
Stackof uninitialized bytes (skipping the cost of first zeroing the stack, which isn't required for a process stack).