Skip to content

Commit

Permalink
Guarantee that raw pointer conversions preserve slice element count
Browse files Browse the repository at this point in the history
This encodes the behavior agreed upon in rust-lang/unsafe-code-guidelines#288.
  • Loading branch information
Tiger0202 committed Oct 11, 2023
1 parent 7401b36 commit 403e09f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/type-coercions.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,16 @@ Coercion is allowed between the following types:

* `!` to any `T`

#### Slice DST raw pointer conversions

When `T` and `U` are both "slice DSTs" - ie, slice types or types whose trailing field
is a slice type - the raw pointer types `*const T`, `*mut T`, `*const U`, and `*mut U`
encode the number of elements in this slice. Coercions between these raw pointer types
preserve the number of elements. Note that, as a consequence, such coercions do *not*
necessarily preserve the size of the pointer's referent (e.g., coercing `*const [u16]`
to `*const [u8]` will result in a raw pointer which refers to an object of half the size
of the original).

### Unsized Coercions

The following coercions are called `unsized coercions`, since they
Expand Down

0 comments on commit 403e09f

Please sign in to comment.