23
23
</div >
24
24
25
25
* Data races.
26
- * Dereferencing (using the ` * ` operator on) a dangling or unaligned raw pointer.
26
+ * Evaluating a [ dereference expression] (` *expr ` ) on a raw pointer that is
27
+ [ dangling] or unaligned, even in [ place expression context]
28
+ (e.g. ` addr_of!(&*expr) ` ).
27
29
* Breaking the [ pointer aliasing rules] . ` &mut T ` and ` &T ` follow LLVM’s scoped
28
30
[ noalias] model, except if the ` &T ` contains an [ ` UnsafeCell<U> ` ] .
29
31
* Mutating immutable data. All data inside a [ ` const ` ] item is immutable. Moreover, all
45
47
* A ` ! ` (all values are invalid for this type).
46
48
* An integer (` i* ` /` u* ` ), floating point value (` f* ` ), or raw pointer obtained
47
49
from [ uninitialized memory] [ undef ] , or uninitialized memory in a ` str ` .
48
- * A reference or ` Box<T> ` that is dangling, unaligned, or points to an invalid value.
50
+ * A reference or ` Box<T> ` that is [ dangling] , unaligned, or points to an invalid value.
49
51
* Invalid metadata in a wide reference, ` Box<T> ` , or raw pointer:
50
52
* ` dyn Trait ` metadata is invalid if it is not a pointer to a vtable for
51
53
` Trait ` that matches the actual dynamic trait the pointer or reference points to.
@@ -62,6 +64,15 @@ a restricted set of valid values. In other words, the only cases in which
62
64
reading uninitialized memory is permitted are inside ` union ` s and in "padding"
63
65
(the gaps between the fields/elements of a type).
64
66
67
+ > ** Note** : Undefined behavior affects the entire program. For example, calling
68
+ > a function in C that exhibits undefined behavior of C means your entire
69
+ > program contains undefined behaviour that can also affect the Rust code. And
70
+ > vice versa, undefined behavior in Rust can cause adverse affects on code
71
+ > executed by any FFI calls to other languages.
72
+
73
+ ### Dangling pointers
74
+ [ dangling ] : #dangling-pointers
75
+
65
76
A reference/pointer is "dangling" if it is null or not all of the bytes it
66
77
points to are part of the same allocation (so in particular they all have to be
67
78
part of * some* allocation). The span of bytes it points to is determined by the
@@ -71,12 +82,6 @@ that slices and strings point to their entire range, so it is important that the
71
82
metadata is never too large. In particular, allocations and therefore slices and strings
72
83
cannot be bigger than ` isize::MAX ` bytes.
73
84
74
- > ** Note** : Undefined behavior affects the entire program. For example, calling
75
- > a function in C that exhibits undefined behavior of C means your entire
76
- > program contains undefined behaviour that can also affect the Rust code. And
77
- > vice versa, undefined behavior in Rust can cause adverse affects on code
78
- > executed by any FFI calls to other languages.
79
-
80
85
[ `bool` ] : types/boolean.md
81
86
[ `const` ] : items/constant-items.md
82
87
[ noalias ] : http://llvm.org/docs/LangRef.html#noalias
@@ -87,3 +92,5 @@ cannot be bigger than `isize::MAX` bytes.
87
92
[ Rustonomicon ] : ../nomicon/index.html
88
93
[ `NonNull<T>` ] : ../core/ptr/struct.NonNull.html
89
94
[ `NonZero*` ] : ../core/num/index.html
95
+ [ dereference expression ] : expressions/operator-expr.md#the-dereference-operator
96
+ [ place expression context ] : expressions.md#place-expressions-and-value-expressions
0 commit comments