Skip to content

Commit

Permalink
Auto merge of #62561 - Centril:rollup-5pxj3bo, r=Centril
Browse files Browse the repository at this point in the history
Rollup of 5 pull requests

Successful merges:

 - #62275 (rustc_mir: treat DropAndReplace as Drop + Assign in qualify_consts.)
 - #62465 (Sometimes generate storage statements for temporaries with type `!`)
 - #62481 (Use `fold` in `Iterator::last` default implementation)
 - #62493 (#62357: doc(ptr): add example for {read,write}_unaligned)
 - #62532 (Some more cleanups to syntax::print)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Jul 10, 2019
2 parents cd2cd4c + 3c299a9 commit 35cacbc
Show file tree
Hide file tree
Showing 24 changed files with 505 additions and 521 deletions.
4 changes: 1 addition & 3 deletions src/libcore/iter/traits/iterator.rs
Expand Up @@ -263,9 +263,7 @@ pub trait Iterator {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
fn last(self) -> Option<Self::Item> where Self: Sized {
let mut last = None;
for x in self { last = Some(x); }
last
self.fold(None, |_, x| Some(x))
}

/// Returns the `n`th element of the iterator.
Expand Down
32 changes: 32 additions & 0 deletions src/libcore/ptr/mod.rs
Expand Up @@ -669,6 +669,22 @@ pub unsafe fn read<T>(src: *const T) -> T {
///
/// Accessing unaligned fields directly with e.g. `packed.unaligned` is safe however.
// FIXME: Update docs based on outcome of RFC #2582 and friends.
///
/// # Examples
///
/// Read an usize value from a byte buffer:
///
/// ```
/// use std::mem;
///
/// fn read_usize(x: &[u8]) -> usize {
/// assert!(x.len() >= mem::size_of::<usize>());
///
/// let ptr = x.as_ptr() as *const usize;
///
/// unsafe { ptr.read_unaligned() }
/// }
/// ```
#[inline]
#[stable(feature = "ptr_unaligned", since = "1.17.0")]
pub unsafe fn read_unaligned<T>(src: *const T) -> T {
Expand Down Expand Up @@ -839,6 +855,22 @@ pub unsafe fn write<T>(dst: *mut T, src: T) {
///
/// Accessing unaligned fields directly with e.g. `packed.unaligned` is safe however.
// FIXME: Update docs based on outcome of RFC #2582 and friends.
///
/// # Examples
///
/// Write an usize value to a byte buffer:
///
/// ```
/// use std::mem;
///
/// fn write_usize(x: &mut [u8], val: usize) {
/// assert!(x.len() >= mem::size_of::<usize>());
///
/// let ptr = x.as_mut_ptr() as *mut usize;
///
/// unsafe { ptr.write_unaligned(val) }
/// }
/// ```
#[inline]
#[stable(feature = "ptr_unaligned", since = "1.17.0")]
pub unsafe fn write_unaligned<T>(dst: *mut T, src: T) {
Expand Down
4 changes: 1 addition & 3 deletions src/librustc/hir/map/mod.rs
Expand Up @@ -1212,10 +1212,8 @@ impl<'a> print::State<'a> {
Node::Pat(a) => self.print_pat(&a),
Node::Arm(a) => self.print_arm(&a),
Node::Block(a) => {
use syntax::print::pprust::PrintState;

// containing cbox, will be closed by print-block at }
self.cbox(print::indent_unit);
self.cbox(print::INDENT_UNIT);
// head-ibox, will be closed by print-block after {
self.ibox(0);
self.print_block(&a)
Expand Down

0 comments on commit 35cacbc

Please sign in to comment.