Skip to content

Commit 228a0fd

Browse files
committed
Add warning about reference validity
1 parent 9471a9a commit 228a0fd

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

reference/src/layout/pointers.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@ and are at least one word.
3232
The layouts of `&T`, `&mut T` and `*T` are the same.
3333

3434
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 - they can be used in C FFI
36-
where pointers are expected.
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.
3741
3842
We do not make any guarantees about the layout of
3943
multi-trait objects `&(dyn T + U)` or references to other dynamically sized types,

0 commit comments

Comments
 (0)