You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/behavior-considered-undefined.md
+12-19
Original file line number
Diff line number
Diff line change
@@ -34,22 +34,18 @@ r[undefined.place-projection]
34
34
[array/slice index expression][project-slice].
35
35
36
36
r[undefined.alias]
37
-
* Breaking the [pointer aliasing rules]. `Box<T>`, `&mut T` and `&T` follow
38
-
LLVM’s scoped [noalias] model, except if the `&T` contains an
39
-
[`UnsafeCell<U>`]. References and boxes must not be [dangling] while they are
40
-
live. The exact liveness duration is not specified, but some bounds exist:
37
+
* Breaking the pointer aliasing rules. The exact aliasing rules are not determined yet, but here is an outline of the general principles:
38
+
`&T` must point to memory that is not mutated while they are live (except for data inside an [`UnsafeCell<U>`]),
39
+
and `&mut T` must point to memory that is not read or written by any pointer not derived from the reference and that no other reference points to while they are live.
40
+
`Box<T>` is treated similar to `&'static mut T` for the purpose of these rules.
41
+
The exact liveness duration is not specified, but some bounds exist:
41
42
* For references, the liveness duration is upper-bounded by the syntactic
42
-
lifetime assigned by the borrow checker; it cannot be live any *longer* than
43
-
that lifetime.
44
-
* Each time a reference or box is passed to or returned from a function, it is
45
-
considered live.
46
-
* When a reference (but not a `Box`!) is passed to a function, it is live at
47
-
least as long as that function call, again except if the `&T` contains an
48
-
[`UnsafeCell<U>`].
49
-
50
-
All this also applies when values of these
51
-
types are passed in a (nested) field of a compound type, but not behind
52
-
pointer indirections.
43
+
lifetime assigned by the borrow checker; it cannot be live any *longer* than that lifetime.
44
+
* Each time a reference or box is dereferenced or reborrowed, it is considered live.
45
+
* Each time a reference or box is passed to or returned from a function, it is considered live.
46
+
* When a reference (but not a `Box`!) is passed to a function, it is live at least as long as that function call, again except if the `&T` contains an [`UnsafeCell<U>`].
47
+
48
+
All this also applies when values of these types are passed in a (nested) field of a compound type, but not behind pointer indirections.
53
49
54
50
r[undefined.immutable]
55
51
* Mutating immutable bytes.
@@ -189,7 +185,7 @@ r[undefined.validity.never]
189
185
190
186
r[undefined.validity.scalar]
191
187
* An integer (`i*`/`u*`), floating point value (`f*`), or raw pointer must be
192
-
initialized, i.e., must not be obtained from [uninitialized memory][undef].
188
+
initialized, i.e., must not be obtained from uninitialized memory.
193
189
194
190
r[undefined.validity.str]
195
191
* A `str` value is treated like `[u8]`, i.e. it must be initialized.
@@ -236,10 +232,7 @@ reading uninitialized memory is permitted are inside `union`s and in "padding"
0 commit comments