Skip to content

Commit 93c626d

Browse files
RalfJungGankra
authored andcommitted
be more precise about dangling
1 parent 447fdb0 commit 93c626d

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/what-unsafe-does.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ to your program. You definitely *should not* invoke Undefined Behavior.
1616
Unlike C, Undefined Behavior is pretty limited in scope in Rust. All the core
1717
language cares about is preventing the following things:
1818

19-
* Dereferencing null, dangling, or unaligned references or raw pointers
19+
* Loading from or storing to null, dangling, or unaligned references or raw
20+
pointers
2021
* Performing out-of-bounds arithmetic for the computation of an
2122
`enum`/`struct`/array/slice/tuple field address
2223
* Reading [uninitialized memory][]
@@ -37,6 +38,10 @@ language cares about is preventing the following things:
3738
"Producing" a value happens any time a value is assigned, passed to a
3839
function/primitive operation or returned from a function/primitive operation.
3940

41+
A reference/pointer is "dangling" if not all of the bytes it points to are part
42+
of the same allocation. The span of bytes it points to is determined by the
43+
pointer value and the size of the pointee type.
44+
4045
That's it. That's all the causes of Undefined Behavior baked into Rust. Of
4146
course, unsafe functions and traits are free to declare arbitrary other
4247
constraints that a program must maintain to avoid Undefined Behavior. For

0 commit comments

Comments
 (0)