Commit 5afc2e4
authored
Rollup merge of rust-lang#136083 - bend-n:⃤⃤, r=lcnr
Suggest {to,from}_ne_bytes for transmutations between arrays and integers, etc
implements rust-lang#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-variousFile tree
10 files changed
+19
-5
lines changed- alloctests/tests
- core/src
- char
- intrinsics
- num
10 files changed
+19
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
221 | 222 | | |
222 | 223 | | |
223 | 224 | | |
| 225 | + | |
224 | 226 | | |
225 | 227 | | |
226 | 228 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1497 | 1497 | | |
1498 | 1498 | | |
1499 | 1499 | | |
| 1500 | + | |
1500 | 1501 | | |
1501 | 1502 | | |
1502 | 1503 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
904 | 904 | | |
905 | 905 | | |
906 | 906 | | |
| 907 | + | |
907 | 908 | | |
908 | 909 | | |
909 | 910 | | |
| |||
951 | 952 | | |
952 | 953 | | |
953 | 954 | | |
| 955 | + | |
954 | 956 | | |
955 | 957 | | |
956 | 958 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
892 | 892 | | |
893 | 893 | | |
894 | 894 | | |
| 895 | + | |
895 | 896 | | |
896 | 897 | | |
897 | 898 | | |
| |||
938 | 939 | | |
939 | 940 | | |
940 | 941 | | |
| 942 | + | |
941 | 943 | | |
942 | 944 | | |
943 | 945 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
710 | 710 | | |
711 | 711 | | |
712 | 712 | | |
713 | | - | |
714 | | - | |
| 713 | + | |
715 | 714 | | |
716 | 715 | | |
717 | 716 | | |
| |||
1097 | 1096 | | |
1098 | 1097 | | |
1099 | 1098 | | |
| 1099 | + | |
1100 | 1100 | | |
1101 | 1101 | | |
1102 | 1102 | | |
| |||
1142 | 1142 | | |
1143 | 1143 | | |
1144 | 1144 | | |
| 1145 | + | |
1145 | 1146 | | |
1146 | 1147 | | |
1147 | 1148 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
718 | 718 | | |
719 | 719 | | |
720 | 720 | | |
721 | | - | |
722 | | - | |
| 721 | + | |
723 | 722 | | |
724 | 723 | | |
725 | 724 | | |
| |||
1095 | 1094 | | |
1096 | 1095 | | |
1097 | 1096 | | |
| 1097 | + | |
1098 | 1098 | | |
1099 | 1099 | | |
1100 | 1100 | | |
| |||
1141 | 1141 | | |
1142 | 1142 | | |
1143 | 1143 | | |
| 1144 | + | |
1144 | 1145 | | |
1145 | 1146 | | |
1146 | 1147 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3675 | 3675 | | |
3676 | 3676 | | |
3677 | 3677 | | |
| 3678 | + | |
3678 | 3679 | | |
3679 | 3680 | | |
3680 | 3681 | | |
| |||
3778 | 3779 | | |
3779 | 3780 | | |
3780 | 3781 | | |
| 3782 | + | |
3781 | 3783 | | |
3782 | 3784 | | |
3783 | 3785 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3523 | 3523 | | |
3524 | 3524 | | |
3525 | 3525 | | |
| 3526 | + | |
3526 | 3527 | | |
3527 | 3528 | | |
3528 | 3529 | | |
| |||
3624 | 3625 | | |
3625 | 3626 | | |
3626 | 3627 | | |
| 3628 | + | |
3627 | 3629 | | |
3628 | 3630 | | |
3629 | 3631 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
0 commit comments