Skip to content

Commit 3657967

Browse files
committed
clarify liveness
1 parent 7110c8e commit 3657967

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/behavior-considered-undefined.md

+14-8
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,20 @@ code.
2626
* Evaluating a [dereference expression] (`*expr`) on a raw pointer that is
2727
[dangling] or unaligned, even in [place expression context]
2828
(e.g. `addr_of!(&*expr)`).
29-
* Breaking the [pointer aliasing rules]. `Box<T>`, `&mut T` and `&T` follow LLVM’s
30-
scoped [noalias] model, except if the `&T` contains an [`UnsafeCell<U>`].
31-
References must not be dangling while they are live. (The exact liveness
32-
duration is not specified, but it is certainly upper-bounded by the syntactic
33-
lifetime assigned by the borrow checker. When a reference is passed to a
34-
function, it is live at least as long as that function call, again except if
35-
the `&T` contains an [`UnsafeCell<U>`].) All this also applies when values of
36-
these types are passed in a (nested) field of a compound type, but not behind
29+
* Breaking the [pointer aliasing rules]. `Box<T>`, `&mut T` and `&T` follow
30+
LLVM’s scoped [noalias] model, except if the `&T` contains an
31+
[`UnsafeCell<U>`]. References and boxes must not be dangling while they are
32+
live. The exact liveness duration is not specified, but some bounds exist:
33+
* For references, the liveness duration is upper-bounded by the syntactic
34+
lifetime assigned by the borrow checker.
35+
* Each time a reference or box is passed to or returned from a function, it is
36+
considered live.
37+
* When a reference (but not a `Box`!) is passed to a function, it is live at
38+
least as long as that function call, again except if the `&T` contains an
39+
[`UnsafeCell<U>`].
40+
41+
All this also applies when values of these
42+
types are passed in a (nested) field of a compound type, but not behind
3743
pointer indirections.
3844
* Mutating immutable data. All data inside a [`const`] item is immutable. Moreover, all
3945
data reached through a shared reference or data owned by an immutable binding

0 commit comments

Comments
 (0)