-
Notifications
You must be signed in to change notification settings - Fork 496
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
elaborate on slice wide pointer metadata #1499
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,12 +71,16 @@ Please read the [Rustonomicon] before writing unsafe code. | |
* A `!` (all values are invalid for this type). | ||
* An integer (`i*`/`u*`), floating point value (`f*`), or raw pointer obtained | ||
from [uninitialized memory][undef], or uninitialized memory in a `str`. | ||
* A reference or `Box<T>` that is [dangling], misaligned, or points to an invalid value. | ||
* Invalid metadata in a wide reference, `Box<T>`, or raw pointer: | ||
* `dyn Trait` metadata is invalid if it is not a pointer to a vtable for | ||
`Trait` that matches the actual dynamic trait the pointer or reference points to. | ||
* Slice metadata is invalid if the length is not a valid `usize` | ||
* A reference or `Box<T>` that is [dangling], misaligned, or points to an invalid value | ||
(in case of dynamically sized types, using the actual dynamic type of the | ||
pointee as determined by the metadata). | ||
* Invalid metadata in a wide reference, `Box<T>`, or raw pointer. The requirement | ||
for the metadata is determined by the type of the unsized tail: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another piece of clarification, previously we were not very clear on what the metadata requirements are for types like |
||
* `dyn Trait` metadata is invalid if it is not a pointer to a vtable for `Trait`. | ||
* Slice (`[T]`) metadata is invalid if the length is not a valid `usize` | ||
(i.e., it must not be read from uninitialized memory). | ||
Furthermore, for wide references and `Box<T>`, slice metadata is invalid | ||
if it makes the total size of the pointed-to value bigger than `isize::MAX`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the only actual change, decided in rust-lang/unsafe-code-guidelines#510. |
||
* Invalid values for a type with a custom definition of invalid values. | ||
In the standard library, this affects [`NonNull<T>`] and [`NonZero*`]. | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"that matches the actual dynamic trait" was clearly nonsense. Also this is now moved to the "points to an invalid value" point since it's not about the metadata, it's about using the metadata to keep going recursively through the reference.