Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guarantee that raw pointer conversions preserve slice element count #1417

Merged
merged 7 commits into from
Nov 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/expressions/operator-expr.md
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,16 @@ unsafe {
assert_eq!(values[1], 3);
```

#### Slice DST pointer to pointer cast

For slice types like `[T]` and `[U]`, the raw pointer types `*const [T]`, `*mut [T]`,
`*const [U]`, and `*mut [U]` encode the number of elements in this slice. Casts between
these raw pointer types preserve the number of elements. Note that, as a consequence,
such casts do *not* necessarily preserve the size of the pointer's referent (e.g.,
casting `*const [u16]` to `*const [u8]` will result in a raw pointer which refers to an
object of half the size of the original). The same holds for `str` and any compound type
whose unsized tail is a slice type, such as struct `Foo(i32, [u8])` or `(u64, Foo)`.

## Assignment expressions

> **<sup>Syntax</sup>**\
Expand Down