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 type `std::mem::MaybeUninit` is a union that represents a potentially uninitialised location in memory.
1673
+
This union has two fields, first `()`, and second `std::mem::ManuallyDrop<T>` which represents the initialised data.
1674
+
When [converting an array to an iterator](https://github.com/rust-lang/rust/blob/a2545fd6fc66b4323f555223a860c451885d1d2b/library/core/src/array/iter.rs#L57-L70)
1675
+
a `Transmute` cast is invoked for the array element type (`T` from `[T; N]`) into `std::mem::MaybeUninit<T>`. Therefore,
1676
+
it is required for iterator use that we handle this transmute. There are details in the safety comment linked above for
1677
+
the safety of this cast. The logic of the semantics and saftey of this cast for us is:
1678
+
- that there is a `Value` to be cast as we cannot construct a `Value` that is not initialised;
1679
+
- that the type being cast from `T` is the same as the type of the unions second field `std::mem::ManuallyDrop<T>`;
1680
+
- we can then then create a union that is constructed with the second field, instantiating the `Value` in a struct;
1681
+
- otherwise we error so that the cast does not `thunk`.
0 commit comments