Skip to content

Commit bc28e64

Browse files
committed
Re-word UB in unsafe guide
This incorrectly implied that doing things is fine in unsafe code Fixes #26346
1 parent 26f0cd5 commit bc28e64

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/doc/trpl/unsafe.md

+14-14
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,21 @@ in the sections marked `unsafe`.
3333

3434
# What does ‘safe’ mean?
3535

36-
Safe, in the context of Rust, means “doesn’t do anything unsafe.” Easy!
36+
Safe, in the context of Rust, means ‘doesn’t do anything unsafe’. It’s also
37+
important to know that there are certain behaviors that are probably not
38+
desirable in your code, but are expressly _not_ unsafe:
3739

38-
Okay, let’s try again: what is not safe to do? Here’s a list:
40+
* Deadlocks
41+
* Leaks of memory or other resources
42+
* Exiting without calling destructors
43+
* Integer overflow
44+
45+
Rust cannot prevent all kinds of software problems. Buggy code can and will be
46+
written in Rust. These things aren’t great, but they don’t qualify as `unsafe`
47+
specifically.
48+
49+
In addition, the following are all undefined behaviors in Rust, and must be
50+
avoided, even when writing `unsafe` code:
3951

4052
* Data races
4153
* Dereferencing a null/dangling raw pointer
@@ -64,18 +76,6 @@ Okay, let’s try again: what is not safe to do? Here’s a list:
6476
[undef]: http://llvm.org/docs/LangRef.html#undefined-values
6577
[aliasing]: http://llvm.org/docs/LangRef.html#pointer-aliasing-rules
6678

67-
Whew! That’s a bunch of stuff. It’s also important to notice all kinds of
68-
behaviors that are certainly bad, but are expressly _not_ unsafe:
69-
70-
* Deadlocks
71-
* Leaks of memory or other resources
72-
* Exiting without calling destructors
73-
* Integer overflow
74-
75-
Rust cannot prevent all kinds of software problems. Buggy code can and will be
76-
written in Rust. These things aren’t great, but they don’t qualify as `unsafe`
77-
specifically.
78-
7979
# Unsafe Superpowers
8080

8181
In both unsafe functions and unsafe blocks, Rust will let you do three things

0 commit comments

Comments
 (0)