about summary refs log tree commit diff
path: root/compiler/rustc_codegen_gcc/example/alloc_example.rs
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-04-24 17:19:42 +0200
committerGitHub <noreply@github.com>2025-04-24 17:19:42 +0200
commit53afa97eb79041572e5c6f07297f4e40f27e972b (patch)
tree519be6cf3b8edf11ed53cbecf1122e4205c78a4d /compiler/rustc_codegen_gcc/example/alloc_example.rs
parent3c877f6a477380ed61155d3bf816df09c9e05b9e (diff)
parent6921a51b4c30d495f8768340d22c44a89e63a782 (diff)
downloadrust-53afa97eb79041572e5c6f07297f4e40f27e972b.tar.gz
rust-53afa97eb79041572e5c6f07297f4e40f27e972b.zip
Rollup merge of #136083 - bend-n:⃤⃤, r=lcnr
Suggest {to,from}_ne_bytes for transmutations between arrays and integers, etc

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.

```rs
fn bytes_at_home(x: [u8; 4]) -> u32 {
   transmute(x)
}

// other examples
transmute::<[u8; 2], u16>();
transmute::<[u8; 8], f64>();
transmute::<u32, [u8; 4]>();
transmute::<char, u32>();
transmute::<u32, char>();
```
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` -> `iXX` via `cast_unsigned` and `cast_signed`
{`char` -> `u32`, `bool` -> `n8`} via `from`
`u32` -> `char` via `from_u32_unchecked` (note: notes `from_u32().unwrap()`) (contested)
`u8` -> `bool` via `==` (debatable)

---
try-job: aarch64-gnu
try-job: test-various
Diffstat (limited to 'compiler/rustc_codegen_gcc/example/alloc_example.rs')
0 files changed, 0 insertions, 0 deletions