Skip to content

Commit e203b97

Browse files
authored
Merge pull request #1290 from RalfJung/aliasing
update aliasing rules section of the reference
2 parents 6a5431b + 2af818d commit e203b97

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/behavior-considered-undefined.md

+16-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,22 @@ 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]. `&mut T` and `&T` follow LLVM’s scoped
30-
[noalias] model, except if the `&T` contains an [`UnsafeCell<U>`].
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; it cannot be live any *longer* than
35+
that lifetime.
36+
* Each time a reference or box is passed to or returned from a function, it is
37+
considered live.
38+
* When a reference (but not a `Box`!) is passed to a function, it is live at
39+
least as long as that function call, again except if the `&T` contains an
40+
[`UnsafeCell<U>`].
41+
42+
All this also applies when values of these
43+
types are passed in a (nested) field of a compound type, but not behind
44+
pointer indirections.
3145
* Mutating immutable data. All data inside a [`const`] item is immutable. Moreover, all
3246
data reached through a shared reference or data owned by an immutable binding
3347
is immutable, unless that data is contained within an [`UnsafeCell<U>`].

0 commit comments

Comments
 (0)