Skip to content

Commit 2a79314

Browse files
authored
Merge pull request #1499 from RalfJung/wide-ptr-meta
elaborate on slice wide pointer metadata
2 parents a45c304 + 4f5888f commit 2a79314

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/behavior-considered-undefined.md

+9-5
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,16 @@ Please read the [Rustonomicon] before writing unsafe code.
7171
* A `!` (all values are invalid for this type).
7272
* An integer (`i*`/`u*`), floating point value (`f*`), or raw pointer obtained
7373
from [uninitialized memory][undef], or uninitialized memory in a `str`.
74-
* A reference or `Box<T>` that is [dangling], misaligned, or points to an invalid value.
75-
* Invalid metadata in a wide reference, `Box<T>`, or raw pointer:
76-
* `dyn Trait` metadata is invalid if it is not a pointer to a vtable for
77-
`Trait` that matches the actual dynamic trait the pointer or reference points to.
78-
* Slice metadata is invalid if the length is not a valid `usize`
74+
* A reference or `Box<T>` that is [dangling], misaligned, or points to an invalid value
75+
(in case of dynamically sized types, using the actual dynamic type of the
76+
pointee as determined by the metadata).
77+
* Invalid metadata in a wide reference, `Box<T>`, or raw pointer. The requirement
78+
for the metadata is determined by the type of the unsized tail:
79+
* `dyn Trait` metadata is invalid if it is not a pointer to a vtable for `Trait`.
80+
* Slice (`[T]`) metadata is invalid if the length is not a valid `usize`
7981
(i.e., it must not be read from uninitialized memory).
82+
Furthermore, for wide references and `Box<T>`, slice metadata is invalid
83+
if it makes the total size of the pointed-to value bigger than `isize::MAX`.
8084
* Invalid values for a type with a custom definition of invalid values.
8185
In the standard library, this affects [`NonNull<T>`] and [`NonZero*`].
8286

0 commit comments

Comments
 (0)