From 0b758f2c0fcf1d7b73b15d83f642f8ec27ab9d6f Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 3 Jul 2026 14:36:14 +0200 Subject: [PATCH] aliasing rules also apply inside private fields, and there are no exceptions to the &mut rule --- src/behavior-considered-undefined.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/behavior-considered-undefined.md b/src/behavior-considered-undefined.md index 28ec9f5ade..f31755ea3b 100644 --- a/src/behavior-considered-undefined.md +++ b/src/behavior-considered-undefined.md @@ -24,7 +24,9 @@ r[undefined.place-projection] r[undefined.alias] * Breaking the pointer aliasing rules. The exact aliasing rules are not determined yet, but here is an outline of the general principles: - `&T` must point to memory that is not mutated while they are live (except for data inside an [`UnsafeCell`]), 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. `Box` is treated similar to `&'static mut T` for the purpose of these rules. The exact liveness duration is not specified, but some bounds exist: + `&T` must point to memory that is not mutated while they are live (except for data inside an [`UnsafeCell`]), 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 (with no exceptions). `Box` is treated similar to `&'static mut T` for the purpose of these rules. These rules apply to *all* references and `Box`, including those stored inside private fields (e.g., if your type has a private field of type `&mut`, that reference must be unique in the sense described above for as long as values of your type are live). + + The exact liveness duration is not specified, but some bounds exist: * For references, the liveness duration is upper-bounded by the syntactic lifetime assigned by the borrow checker; it cannot be live any *longer* than that lifetime. * Each time a reference or box is dereferenced or reborrowed, it is considered live.