@@ -27,13 +27,19 @@ In this case, both `r` and `s` alias each other, since they both point to all of
27
27
the bytes of ` u ` .
28
28
29
29
However, ` head ` and ` tail ` do not alias each other: ` head ` points to the first
30
- byte of ` u ` and ` tail ` points to the other seven bytes of ` u ` after it. Also,
31
- both ` head ` and ` tail ` alias ` s ` .
32
-
33
- * The span length of ` &T ` , ` &mut T ` , ` *const T ` , or ` *mut T ` when ` T ` is
34
- [ ` Sized ` ] ( https://doc.rust-lang.org/core/marker/trait.Sized.html ) is
35
- ` size_of<T>() ` .
36
- * When ` T ` is not ` Sized ` the span length is ` size_of_val(t) ` .
30
+ byte of ` u ` and ` tail ` points to the other seven bytes of ` u ` after it. Both ` head `
31
+ and ` tail ` alias ` s ` , any overlap is sufficient to count as an alias.
32
+
33
+ * The span of a pointer or reference is the size of the value being pointed to or referenced.
34
+ * For some type ` T ` that is [ ` Sized ` ] ( https://doc.rust-lang.org/core/marker/trait.Sized.html )
35
+ The span length of a pointer or reference to ` T ` is found with ` size_of::<T>() ` .
36
+ * When ` T ` is not ` Sized ` the story is a little tricker:
37
+ * If you have a reference ` r ` you can use ` size_of_val(r) ` to determine the
38
+ span of the reference.
39
+ * If you have a pointer ` p ` you must unsafely convert that to a reference before
40
+ you can use ` size_of_val ` . There is not currently a safe way to determine the
41
+ span of a pointer to an unsized type.
42
+ * The Data Layout chapter also has more information on the sizes of different types.
37
43
38
44
One interesting side effect of these rules is that references and pointers to
39
45
Zero Sized Types _ never_ alias each other, because their span length is always 0
@@ -123,4 +129,4 @@ niche.
123
129
* * tag*
124
130
* * rvalue*
125
131
* * lvalue*
126
- * * representation*
132
+ * * representation*
0 commit comments