blob: 29db9258e83fb3cd17c4c00ab011997000b06c41 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
### What it does
Checks for transmutes between collections whose
types have different ABI, size or alignment.
### Why is this bad?
This is undefined behavior.
### Known problems
Currently, we cannot know whether a type is a
collection, so we just lint the ones that come with `std`.
### Example
```
// different size, therefore likely out-of-bounds memory access
// You absolutely do not want this in your code!
unsafe {
std::mem::transmute::<_, Vec<u32>>(vec![2_u16])
};
```
You must always iterate, map and collect the values:
```
vec![2_u16].into_iter().map(u32::from).collect::<Vec<_>>();
```
|