Skip to content

Commit 9f2e32e

Browse files
authored
Improve the explanation of how to find the span.
1 parent b4ae21f commit 9f2e32e

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

reference/src/glossary.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,19 @@ In this case, both `r` and `s` alias each other, since they both point to all of
2727
the bytes of `u`.
2828

2929
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.
3743

3844
One interesting side effect of these rules is that references and pointers to
3945
Zero Sized Types _never_ alias each other, because their span length is always 0
@@ -123,4 +129,4 @@ niche.
123129
* *tag*
124130
* *rvalue*
125131
* *lvalue*
126-
* *representation*
132+
* *representation*

0 commit comments

Comments
 (0)