Skip to content

Commit c541c0a

Browse files
authored
Merge pull request #100 from gnzlbg/raw_pointer_sized
Note the layout of pointers to T:Sized matches that of C pointers
2 parents 76c96f9 + 228a0fd commit c541c0a

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

reference/src/layout/pointers.md

+8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ and are at least one word.
3131

3232
The layouts of `&T`, `&mut T` and `*T` are the same.
3333

34+
If `T` is sized, references and pointers to `T` have a size and alignment of one
35+
word and have therefore the same layout as C pointers.
36+
37+
> **warning**: while the layout of references and pointers is compatible with
38+
> the layout of C pointers, references come with a _validity_ invariant that
39+
> does not allow them to be used when they could be `NULL`, unaligned, dangling,
40+
> or, in the case of `&mut T`, aliasing.
41+
3442
We do not make any guarantees about the layout of
3543
multi-trait objects `&(dyn T + U)` or references to other dynamically sized types,
3644
other than that they are at least word-aligned, and have size at least one word.

0 commit comments

Comments
 (0)