Skip to content

Commit c147c8a

Browse files
committed
rebase the reference diff
1 parent baf3d9c commit c147c8a

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

text/0000-maybe-dangling.md

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -128,24 +128,22 @@ The standard library contains a type `MaybeDangling<P>` that is safely convertib
128128
"Behavior considered undefined" is adjusted as follows:
129129

130130
```diff
131-
- * Breaking the pointer aliasing rules. `&mut T` and `&T` follow LLVM’s
132-
- scoped noalias model, except if the &T contains an UnsafeCell<U>.
133-
+ * Breaking the pointer aliasing rules. `Box<T>`, `&mut T` and `&T` follow LLVM’s
134-
+ scoped noalias model, except for `UnsafeCell<_>` inside the `T`.
135-
+ References must not be dangling while they are live, again except for
136-
+ `UnsafeCell<_>` inside the `T`. (The exact liveness duration is not
137-
+ specified, but it is certainly upper-bounded by the syntactic lifetime
138-
+ assigned by the borrow checker. When a reference is passed to a function,
139-
+ it is live at least as long as that function call.) All this also
140-
+ applies when values of these types are passed in a field of a compund
141-
+ type, except behind pointer indirections and when the pointers or
142-
+ references are inside `MaybeDangling`.
131+
* Breaking the [pointer aliasing rules]. `Box<T>`, `&mut T` and `&T` follow LLVM’s
132+
scoped noalias model, except if the `&T` contains an [`UnsafeCell<U>`].
133+
References must not be dangling while they are live. (The exact liveness
134+
duration is not specified, but it is certainly upper-bounded by the syntactic
135+
lifetime assigned by the borrow checker. When a reference is passed to a
136+
function, it is live at least as long as that function call, again except if
137+
the `&T` contains an [`UnsafeCell<U>`].) All this also applies when values of
138+
these types are passed in a (nested) field of a compound type, but not behind
139+
- pointer indirections.
140+
+ pointer indirections and also not for values inside a `MaybeDangling<_>`.
143141
[...]
144-
* Producing an invalid value, even in private fields and locals.
145-
"Producing" a value happens any time a value is assigned to or
146-
read from a place, passed to a function/primitive operation or
147-
returned from a function/primitive operation. The following
148-
values are invalid (at their respective type):
142+
* Producing an invalid value, even in private fields and locals.
143+
"Producing" a value happens any time a value is assigned to or
144+
read from a place, passed to a function/primitive operation or
145+
returned from a function/primitive operation. The following
146+
values are invalid (at their respective type):
149147
[...]
150148
- * A reference or Box<T> that is dangling, unaligned, or points to an
151149
- invalid value.
@@ -155,7 +153,7 @@ The standard library contains a type `MaybeDangling<P>` that is safely convertib
155153
+ to an invalid value, it is itself invalid.
156154
```
157155

158-
*Note: this might seem to alter the aliasing rules compared to the current reference more than just by adding a `MaybeDangling` exception (specifically when it talks about the liveness duration of references), but really it just clarifies semnatics we have applied since Rust 1.0, and incorporates [#98017](https://github.com/rust-lang/rust/pull/98017).*
156+
*Note: this diff is based on [an updated version of the referece](https://github.com/rust-lang/reference/pull/1290).*
159157

160158
Another way to think about this is: most types only have "by-value" requirements for their validity, i.e., they only require that the bit pattern be of a certain shape.
161159
References and boxes are the sole exception, they also require some properties of the memory they point to (e.g., they need to be dereferenceable).

0 commit comments

Comments
 (0)