-
Notifications
You must be signed in to change notification settings - Fork 4
Transmute integer to fieldless enum #840
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
automergerpr-permission-manager
merged 9 commits into
master
from
dc/cast-u8-to-enum-fieldless
Nov 15, 2025
Merged
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9e81b90
Added test for transmuting integer to fieldless enum
dkcumming 0bca0e9
Added some validation that the cast is same size and signedness
dkcumming dbce69a
Added symbolic test to show unsound branch
dkcumming 4e010d4
Added tests and corrected rules:
dkcumming 830e45c
Removed `#tagCompatible` and special rule for discriminants with thunk
dkcumming a31513c
Changed `#validDiscriminantAux` to process disjunction to avoid branch
dkcumming c1aff19
Changed rules to work with unsigned numbers and added some more tests
dkcumming 9d1dfa6
Updated documentation
dkcumming 010cda4
Merge branch 'master' into dc/cast-u8-to-enum-fieldless
dkcumming File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
15 changes: 15 additions & 0 deletions
15
kmir/src/tests/integration/data/prove-rs/transmute-u8-to-enum.rs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #[repr(u8)] | ||
| #[derive(Clone, Copy, Debug, PartialEq)] | ||
| pub enum AccountState { | ||
| Uninitialized, | ||
| Initialized, | ||
| Frozen, | ||
| } | ||
|
|
||
| fn main() { | ||
| unsafe { | ||
| assert_eq!(core::mem::transmute::<u8, AccountState>(0), AccountState::Uninitialized); | ||
| assert_eq!(core::mem::transmute::<u8, AccountState>(1), AccountState::Initialized); | ||
| assert_eq!(core::mem::transmute::<u8, AccountState>(2), AccountState::Frozen); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.