Skip to content

Commit 104da42

Browse files
authored
Merge pull request #377 from Havvy/unsafe-warning
Warning about UB being not being complete
2 parents c64a253 + a526136 commit 104da42

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/behavior-considered-undefined.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ if it exhibits any of the behaviors in the following list. It is the
55
programmer's responsibility when writing `unsafe` code that it is not possible
66
to let `safe` code exhibit these behaviors.
77

8+
<div class="warning">
9+
10+
***Warning:*** The following list is not exhaustive. There is no formal model of
11+
Rust's semantics for what is and is not allowed in unsafe code, so there may be
12+
more behavior considered unsafe. The following list is just what we know for
13+
sure is undefined behavior. Please read the [Rustonomicon] before writing unsafe
14+
code.
15+
16+
</div>
17+
818
* Data races.
919
* Dereferencing a null or dangling raw pointer.
1020
* Unaligned pointer reading and writing outside of [`read_unaligned`]
@@ -37,3 +47,4 @@ to let `safe` code exhibit these behaviors.
3747
[`UnsafeCell<U>`]: https://doc.rust-lang.org/std/cell/struct.UnsafeCell.html
3848
[`read_unaligned`]: https://doc.rust-lang.org/std/ptr/fn.read_unaligned.html
3949
[`write_unaligned`]: https://doc.rust-lang.org/std/ptr/fn.write_unaligned.html
50+
[Rustonomicon]: ../nomicon

src/unsafety.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Unsafety
22

3-
Unsafe operations are those that potentially violate the memory-safety
3+
Unsafe operations are those that can potentially violate the memory-safety
44
guarantees of Rust's static semantics.
55

66
The following language level features cannot be used in the safe subset of
@@ -11,4 +11,4 @@ Rust:
1111
- Reading a field of a [`union`](items/unions.html), or writing to a field of a
1212
union that isn't [`Copy`](special-types-and-traits.html#copy).
1313
- Calling an unsafe function (including an intrinsic or foreign function).
14-
- Implementing an unsafe trait.
14+
- Implementing an unsafe trait.

0 commit comments

Comments
 (0)