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

Rollup of 10 pull requests #62378

Closed
Closed
Changes from 3 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
bb26e07
Add debug assertions to write_bytes and copy*
nitnelave Feb 27, 2019
0533f12
Handle null from LLVMRustGetSectionName
nitnelave Mar 27, 2019
8a4573f
format a bit
RalfJung Jun 24, 2019
4159b27
order things more traditionally
RalfJung Jun 24, 2019
a68afc5
ignore some codegen tests in debug mode
RalfJung Jun 25, 2019
d3e1bf9
nits
RalfJung Jun 25, 2019
0ffb643
Make sure `#[rustc_doc_only_macro]` and other rustc attributes are re…
petrochenkov Jun 29, 2019
e4e7eb2
Feature gate `rustc` attributes harder
petrochenkov Jun 30, 2019
47ea8ae
Remove needless lifetimes
jeremystucki Jun 25, 2019
ec8c2e1
Use a single CtxtInterners
Zoxc May 31, 2019
b9344e3
Derive which queries to save using the proc macro
Zoxc Jun 27, 2019
bb7fbb9
Add separate 'async_closure' feature gate.
Centril Jul 2, 2019
43315bc
Adjust tests wrt. 'async_closure' feature gate.
Centril Jul 2, 2019
3eef0cb
Reduce reliance on feature(await_macro).
Centril Jul 3, 2019
bee964c
Clarify unaligned fields in ptr::read_unaligned.
Centril Jul 3, 2019
54527db
ptr::{read,write}_unaligned: use no_run and reword slightly.
Centril Jul 4, 2019
fc67e57
Add missing lifetime specifier
jeremystucki Jul 4, 2019
55bd214
Add tracking issue for Box::into_pin
Nemo157 Jul 4, 2019
e4f250e
Implement mem::{zeroed,uninitialized} in terms of MaybeUninit.
alex Jun 26, 2019
41a85b0
Rollup merge of #61392 - Zoxc:single-interner, r=eddyb
Mark-Simulacrum Jul 4, 2019
b208172
Rollup merge of #62103 - RalfJung:debug-assert, r=alexcrichton
Mark-Simulacrum Jul 4, 2019
73fa329
Rollup merge of #62123 - jeremystucki:needless_lifetimes_std, r=alexc…
Mark-Simulacrum Jul 4, 2019
2a374b0
Rollup merge of #62133 - petrochenkov:norustc, r=eddyb
Mark-Simulacrum Jul 4, 2019
aa1e9be
Rollup merge of #62150 - alex:mem-uninit-refactor, r=RalfJung
Mark-Simulacrum Jul 4, 2019
13fff3d
Rollup merge of #62169 - Zoxc:store-query-results, r=eddyb
Mark-Simulacrum Jul 4, 2019
6a2da57
Rollup merge of #62292 - Centril:split-async-closures, r=cramertj
Mark-Simulacrum Jul 4, 2019
cabf8b0
Rollup merge of #62323 - Centril:clarify-read-unaligned, r=RalfJung
Mark-Simulacrum Jul 4, 2019
2461040
Rollup merge of #62324 - Centril:reduce-await-macro-reliance, r=cramertj
Mark-Simulacrum Jul 4, 2019
167429f
Rollup merge of #62371 - Nemo157:fix-62288, r=Centril
Mark-Simulacrum Jul 4, 2019
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
88 changes: 53 additions & 35 deletions src/libcore/ptr/mod.rs
Original file line number Diff line number Diff line change
@@ -625,42 +625,50 @@ pub unsafe fn read<T>(src: *const T) -> T {
/// [read-ownership]: ./fn.read.html#ownership-of-the-returned-value
/// [valid]: ../ptr/index.html#safety
///
/// # Examples
/// ## On `packed` structs
///
/// Access members of a packed struct by reference:
/// It is currently impossible to create raw pointers to unaligned fields
/// of a packed struct.
///
/// ```
/// use std::ptr;
/// Attempting to create a raw pointer to an `unaligned` struct field with
/// an expression such as `&packed.unaligned as *const FieldType` creates an
/// intermediate unaligned reference before converting that to a raw pointer.
/// That this reference is temporary and immediately cast is inconsequential
/// as the compiler always expects references to be properly aligned.
/// As a result, using `&packed.unaligned as *const FieldType` causes immediate
/// *undefined behavior* in your program.
///
/// An example of what not to do and how this relates to `read_unaligned` is:
///
/// ```no_run
/// #[repr(packed, C)]
/// struct Packed {
/// _padding: u8,
/// unaligned: u32,
/// }
///
/// let x = Packed {
/// let packed = Packed {
/// _padding: 0x00,
/// unaligned: 0x01020304,
/// };
///
/// let v = unsafe {
/// // Take the address of a 32-bit integer which is not aligned.
/// // This must be done as a raw pointer; unaligned references are invalid.
/// let unaligned = &x.unaligned as *const u32;
///
/// // Dereferencing normally will emit an aligned load instruction,
/// // causing undefined behavior.
/// // let v = *unaligned; // ERROR
/// // Here we attempt to take the address of a 32-bit integer which is not aligned.
/// let unaligned =
/// // A temporary unaligned reference is created here which results in
/// // undefined behavior regardless of whether the reference is used or not.
/// &packed.unaligned
/// // Casting to a raw pointer doesn't help; the mistake already happened.
/// as *const u32;
///
/// // Instead, use `read_unaligned` to read improperly aligned values.
/// let v = ptr::read_unaligned(unaligned);
/// let v = std::ptr::read_unaligned(unaligned);
///
/// v
/// };
///
/// // Accessing unaligned values directly is safe.
/// assert!(x.unaligned == v);
/// ```
///
/// Accessing unaligned fields directly with e.g. `packed.unaligned` is safe however.
// FIXME: Update docs based on outcome of RFC #2582 and friends.
#[inline]
#[stable(feature = "ptr_unaligned", since = "1.17.0")]
pub unsafe fn read_unaligned<T>(src: *const T) -> T {
@@ -789,38 +797,48 @@ pub unsafe fn write<T>(dst: *mut T, src: T) {
///
/// [valid]: ../ptr/index.html#safety
///
/// # Examples
/// ## On `packed` structs
///
/// Access fields in a packed struct:
/// It is currently impossible to create raw pointers to unaligned fields
/// of a packed struct.
///
/// ```
/// use std::{mem, ptr};
/// Attempting to create a raw pointer to an `unaligned` struct field with
/// an expression such as `&packed.unaligned as *const FieldType` creates an
/// intermediate unaligned reference before converting that to a raw pointer.
/// That this reference is temporary and immediately cast is inconsequential
/// as the compiler always expects references to be properly aligned.
/// As a result, using `&packed.unaligned as *const FieldType` causes immediate
/// *undefined behavior* in your program.
///
/// An example of what not to do and how this relates to `write_unaligned` is:
///
/// ```no_run
/// #[repr(packed, C)]
/// #[derive(Default)]
/// struct Packed {
/// _padding: u8,
/// unaligned: u32,
/// }
///
/// let v = 0x01020304;
/// let mut x: Packed = unsafe { mem::zeroed() };
///
/// unsafe {
/// // Take a reference to a 32-bit integer which is not aligned.
/// let unaligned = &mut x.unaligned as *mut u32;
/// let mut packed: Packed = unsafe { std::mem::zeroed() };
///
/// // Dereferencing normally will emit an aligned store instruction,
/// // causing undefined behavior because the pointer is not aligned.
/// // *unaligned = v; // ERROR
/// let v = unsafe {
/// // Here we attempt to take the address of a 32-bit integer which is not aligned.
/// let unaligned =
/// // A temporary unaligned reference is created here which results in
/// // undefined behavior regardless of whether the reference is used or not.
/// &mut packed.unaligned
/// // Casting to a raw pointer doesn't help; the mistake already happened.
/// as *mut u32;
///
/// // Instead, use `write_unaligned` to write improperly aligned values.
/// ptr::write_unaligned(unaligned, v);
/// }
/// std::ptr::write_unaligned(unaligned, v);
///
/// // Accessing unaligned values directly is safe.
/// assert!(x.unaligned == v);
/// v
/// };
/// ```
///
/// Accessing unaligned fields directly with e.g. `packed.unaligned` is safe however.
// FIXME: Update docs based on outcome of RFC #2582 and friends.
#[inline]
#[stable(feature = "ptr_unaligned", since = "1.17.0")]
pub unsafe fn write_unaligned<T>(dst: *mut T, src: T) {