Skip to content

Commit d7c2815

Browse files
authored
Merge pull request #242 from camelid/improve-transmutes
Improve formatting of "Transmutes" chapter
2 parents 8627458 + ebe16b1 commit d7c2815

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/transmutes.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,24 @@ boggling.
1515
is going to cause arbitrary chaos that can't really be predicted. Do not
1616
transmute `3` to `bool`. Even if you never *do* anything with the `bool`. Just
1717
don't.
18+
1819
* Transmute has an overloaded return type. If you do not specify the return type
1920
it may produce a surprising type to satisfy inference.
20-
* Transmuting an & to &mut is UB.
21-
* Transmuting an & to &mut is *always* UB.
21+
22+
* Transmuting an `&` to `&mut` is UB.
23+
* Transmuting an `&` to `&mut` is *always* UB.
2224
* No you can't do it.
2325
* No you're not special.
26+
2427
* Transmuting to a reference without an explicitly provided lifetime
25-
produces an [unbounded lifetime]
28+
produces an [unbounded lifetime].
29+
2630
* When transmuting between different compound types, you have to make sure they
2731
are laid out the same way! If layouts differ, the wrong fields are going to
2832
get filled with the wrong data, which will make you unhappy and can also be UB
2933
(see above).
3034

31-
So how do you know if the layouts are the same? For `repr(C)` types and
35+
So how do you know if the layouts are the same? For `repr(C)` types and
3236
`repr(transparent)` types, layout is precisely defined. But for your
3337
run-of-the-mill `repr(Rust)`, it is not. Even different instances of the same
3438
generic type can have wildly different layout. `Vec<i32>` and `Vec<u32>`
@@ -47,7 +51,7 @@ pointer casts or `union`s, but without any of the lints or other basic sanity
4751
checks. Raw pointer casts and `union`s do not magically avoid the above rules.
4852

4953

50-
[unbounded lifetime]: unbounded-lifetimes.html
54+
[unbounded lifetime]: ./unbounded-lifetimes.md
5155
[transmute]: ../std/mem/fn.transmute.html
5256
[transmute_copy]: ../std/mem/fn.transmute_copy.html
5357
[ucg-layout]: https://rust-lang.github.io/unsafe-code-guidelines/layout.html

0 commit comments

Comments
 (0)