Fix unnecessary transmute and unnecessary unsafe block warnings on bitfield codegen#3388
Merged
emilio merged 2 commits intoJul 6, 2026
Merged
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
41d933d to
872606a
Compare
Collaborator
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
872606a to
f12117a
Compare
Contributor
Author
|
r? @emilio |
emilio
approved these changes
Jul 6, 2026
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.
Fixes #2807 , Fixes #3355 (=#3241 (comment))
PR #3335 replaced
transmutewithas _in the union branch getter/setter and the non-union setter, and removed the unsafe block from the union branch. It left non-union getter and raw getter, emittingunsafe { transmute(...) }and triggeringunnecessary_transmuteswarning for integer (#2807). It replacedtransmutewithval as _for non-union setter and keptunsafeblock which is required for Rust unions (its field access is unsafe) but redundant for the rest of cases (#3355).This PR type-dispatches the non-union getter codegen, and removes unnecessary unsafe block from the non-union setter. It dispatches on
bitfield_ty.canonical_type(ctx).kind()instead ofbitfield_ty.kind()to resolveAlias/Elaboratedwrappers clang applies.unsafe { transmute(get_const() as u32) }(unnecessary transmutes) ->get_const() as u32 as _unsafe { transmute(get_const() as u8) }->get_const() as u8 != 0unsafe { transmute(get_const() as u32) }unsafe { let val: u32 = val as _; self._bitfield_1.set_const(val as u64) }let val: u32 = val as _; self._bitfield_1.set_const(val as u64)