Updates from master#869
Merged
Merged
Conversation
#### Context Motivated by [iterator-simple-fail.rs](https://github.com/runtimeverification/mir-semantics/blob/3d763c00389dcdb45a68523d6515c6d6fc8b2928/kmir/src/tests/integration/data/prove-rs/iterator-simple-fail.rs#L1-L7) (which should pass). The type [std::mem::MaybeUninit](https://doc.rust-lang.org/std/mem/union.MaybeUninit.html) is a union that represents a potentially uninitialised location in memory. This union has two fields, first `()`, and second [std::mem::ManuallyDrop<T>](https://doc.rust-lang.org/std/mem/struct.ManuallyDrop.html) which represents the initialised data. When [converting an array to an iterator](https://github.com/rust-lang/rust/blob/a2545fd6fc66b4323f555223a860c451885d1d2b/library/core/src/array/iter.rs#L57-L70) a `Transmute` cast is invoked for the array element type (`T` from `[T; N]`) into `std::mem::MaybeUninit<T>`. #### This PR This PR implements the cast `CastKind::Transmute` of `T` into `std::mem:MaybeUninit<T>`. The logic of the semantics and saftey of this cast for us is: - that there is a `Value` to be cast as we cannot construct a `Value` that is not initialised; - that the type being cast from `T` is the same as the type of the unions second field `std::mem::ManuallyDrop<T>`; - we can then then create a union that is constructed with the second field, instantiating the `Value` in a struct; - otherwise we error so that the cast does not `thunk`. Tests are added to show the passing cases for `transmute` and `transmute_unchecked`, and the failing case where the types are not valid for the transmute as explained above. A follow up PR will handle converting the elements of the array when an array, this PR is just for a single element.
dkcumming
approved these changes
Nov 27, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CastKind::TransmuteforT -> std::mem::MaybeUninit<T>(CastKind::TransmuteforT -> std::mem::MaybeUninit<T>#863) - single element case