Skip to content

Commit cd8193e

Browse files
authored
Merge pull request #1417 from joshlf/patch-3
Guarantee that raw pointer conversions preserve slice element count
2 parents b8a39d3 + ad09bb0 commit cd8193e

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/expressions/operator-expr.md

+10
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,16 @@ unsafe {
478478
assert_eq!(values[1], 3);
479479
```
480480

481+
#### Slice DST pointer to pointer cast
482+
483+
For slice types like `[T]` and `[U]`, the raw pointer types `*const [T]`, `*mut [T]`,
484+
`*const [U]`, and `*mut [U]` encode the number of elements in this slice. Casts between
485+
these raw pointer types preserve the number of elements. Note that, as a consequence,
486+
such casts do *not* necessarily preserve the size of the pointer's referent (e.g.,
487+
casting `*const [u16]` to `*const [u8]` will result in a raw pointer which refers to an
488+
object of half the size of the original). The same holds for `str` and any compound type
489+
whose unsized tail is a slice type, such as struct `Foo(i32, [u8])` or `(u64, Foo)`.
490+
481491
## Assignment expressions
482492

483493
> **<sup>Syntax</sup>**\

0 commit comments

Comments
 (0)