Suggest {to,from}_ne_bytes for transmutations between arrays and integers, etc#136083
Merged
bors merged 2 commits intorust-lang:masterfrom Apr 24, 2025
Hidden character warning
The head ref may contain hidden characters: "\u20e4\u20e4"
Merged
Suggest {to,from}_ne_bytes for transmutations between arrays and integers, etc#136083bors merged 2 commits intorust-lang:masterfrom
bors merged 2 commits intorust-lang:masterfrom
Conversation
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.
implements #136067
Rust has helper methods for many kinds of safe transmutes, for example integer<->bytes. This is a lint against using transmute for these cases.
It would be handy to suggest
u32::from_ne_bytes(x).This is implemented for
[u8; _]->{float int}This also implements the cases:
fXX<->uXX={from_bits, to_bits}uXX->iXXviacast_unsignedandcast_signed{
char->u32,bool->n8} viafromu32->charviafrom_u32_unchecked(note: notesfrom_u32().unwrap()) (contested)u8->boolvia==(debatable)try-job: aarch64-gnu
try-job: test-various