You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The reason it will fail is because ArrayDeque::new() is using mem::uninitialized to create the array itself, which is discouraged because the resulting value will tend to yield undefined behavior unless the type is valid for all possible bit patterns. (And an easy example of a type that is not valid for all possible bit patterns is Box<T>, since it must be non-null.)
The test above is demonstrating how violating this rule can break invariants like Some(E).is_some() for any E.
One potential fix for this has been pointed out by oli: Use an untagged union instead of mem::uninitialized.
Another potential fix would be to use MaybeUninit instead of ManuallyDrop, as pointed out by nagisa.
Neither of these fixes is available in stable Rust today, though. (untagged unions only support Copy data if you're on stable.)
The text was updated successfully, but these errors were encountered:
Spawned from rust-lang/rust#58684
The following test is likely to fail in the current code base, at least for many versions of
rustc
.The reason it will fail is because
ArrayDeque::new()
is usingmem::uninitialized
to create the array itself, which is discouraged because the resulting value will tend to yield undefined behavior unless the type is valid for all possible bit patterns. (And an easy example of a type that is not valid for all possible bit patterns isBox<T>
, since it must be non-null.)The test above is demonstrating how violating this rule can break invariants like
Some(E).is_some()
for anyE
.mem::uninitialized
.MaybeUninit
instead ofManuallyDrop
, as pointed out by nagisa.Neither of these fixes is available in stable Rust today, though. (untagged unions only support
Copy
data if you're on stable.)The text was updated successfully, but these errors were encountered: