Skip to content

Rewrite docs for std::ptr #49767

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

Merged
merged 9 commits into from
May 15, 2018
Prev Previous commit
Next Next commit
Change write_bytes test causing UB to no_run
This also fixes improper text wrapping.
  • Loading branch information
ecstatic-morse committed Apr 7, 2018
commit ee259e4dd340f9532511b7249e4eb961f111b63f
13 changes: 7 additions & 6 deletions src/libcore/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -992,11 +992,11 @@ extern "rust-intrinsic" {
///
/// * The two regions of memory must *not* overlap.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be at the top, since all the other conditions are just "things that are true of any pointer accesses" (which suggests to me that they can potentially be omitted or centralized in the top-level module documentation and just linked?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be a good idea to document the requirements for stores and loads at the top-level. My concern was that people coming to the docs from a search engine may not see the top-level documentation. There was also talk in #36450 of specifying alignment requirements for every function in std::ptr.

I'd like some clarification on what the precise requirements for loads and stores are regarding initializing memory, and what the precise definition of "valid" memory is.

///
/// Additionally, if `T` is not [`Copy`](../marker/trait.Copy), only the region at `src` *or* the
/// region at `dst` can be used or dropped after calling
/// `copy_nonoverlapping`. `copy_nonoverlapping` creates bitwise copies of
/// `T`, regardless of whether `T: Copy`, which can result in undefined
/// behavior if both copies are used.
/// Additionally, if `T` is not [`Copy`](../marker/trait.Copy), only the
/// region at `src` *or* the region at `dst` can be used or dropped after
/// calling `copy_nonoverlapping`. `copy_nonoverlapping` creates bitwise
/// copies of `T`, regardless of whether `T: Copy`, which can result in
/// undefined behavior if both copies are used.
///
/// [Undefined Behavior]: ../../reference/behavior-considered-undefined.html
///
Expand Down Expand Up @@ -1149,7 +1149,7 @@ extern "rust-intrinsic" {
///
/// Creating an invalid value:
///
/// ```ignore
/// ```no_run
/// use std::{mem, ptr};
///
/// let mut v = Box::new(0i32);
Expand All @@ -1161,6 +1161,7 @@ extern "rust-intrinsic" {
/// }
///
/// // At this point, using or dropping `v` results in undefined behavior.
/// // v = Box::new(0i32); // ERROR
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn write_bytes<T>(dst: *mut T, val: u8, count: usize);
Expand Down