@@ -15,20 +15,24 @@ boggling.
15
15
is going to cause arbitrary chaos that can't really be predicted. Do not
16
16
transmute ` 3 ` to ` bool ` . Even if you never * do* anything with the ` bool ` . Just
17
17
don't.
18
+
18
19
* Transmute has an overloaded return type. If you do not specify the return type
19
20
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.
22
24
* No you can't do it.
23
25
* No you're not special.
26
+
24
27
* Transmuting to a reference without an explicitly provided lifetime
25
- produces an [ unbounded lifetime]
28
+ produces an [ unbounded lifetime] .
29
+
26
30
* When transmuting between different compound types, you have to make sure they
27
31
are laid out the same way! If layouts differ, the wrong fields are going to
28
32
get filled with the wrong data, which will make you unhappy and can also be UB
29
33
(see above).
30
34
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
32
36
` repr(transparent) ` types, layout is precisely defined. But for your
33
37
run-of-the-mill ` repr(Rust) ` , it is not. Even different instances of the same
34
38
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
47
51
checks. Raw pointer casts and ` union ` s do not magically avoid the above rules.
48
52
49
53
50
- [ unbounded lifetime ] : unbounded-lifetimes.html
54
+ [ unbounded lifetime ] : ./ unbounded-lifetimes.md
51
55
[ transmute ] : ../std/mem/fn.transmute.html
52
56
[ transmute_copy ] : ../std/mem/fn.transmute_copy.html
53
57
[ ucg-layout ] : https://rust-lang.github.io/unsafe-code-guidelines/layout.html
0 commit comments