@@ -33,9 +33,21 @@ in the sections marked `unsafe`.
33
33
34
34
# What does ‘safe’ mean?
35
35
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:
37
39
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:
39
51
40
52
* Data races
41
53
* 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:
64
76
[ undef ] : http://llvm.org/docs/LangRef.html#undefined-values
65
77
[ aliasing ] : http://llvm.org/docs/LangRef.html#pointer-aliasing-rules
66
78
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
-
79
79
# Unsafe Superpowers
80
80
81
81
In both unsafe functions and unsafe blocks, Rust will let you do three things
0 commit comments