Skip to content

Commit 0f7c4e6

Browse files
committed
Auto merge of #62561 - Centril:rollup-5pxj3bo, r=Centril
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
2 parents c6a9e76 + 3c299a9 commit 0f7c4e6

File tree

24 files changed

+505
-521
lines changed

24 files changed

+505
-521
lines changed

src/libcore/iter/traits/iterator.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,7 @@ pub trait Iterator {
263263
#[inline]
264264
#[stable(feature = "rust1", since = "1.0.0")]
265265
fn last(self) -> Option<Self::Item> where Self: Sized {
266-
let mut last = None;
267-
for x in self { last = Some(x); }
268-
last
266+
self.fold(None, |_, x| Some(x))
269267
}
270268

271269
/// Returns the `n`th element of the iterator.

src/libcore/ptr/mod.rs

+32
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,22 @@ pub unsafe fn read<T>(src: *const T) -> T {
669669
///
670670
/// Accessing unaligned fields directly with e.g. `packed.unaligned` is safe however.
671671
// FIXME: Update docs based on outcome of RFC #2582 and friends.
672+
///
673+
/// # Examples
674+
///
675+
/// Read an usize value from a byte buffer:
676+
///
677+
/// ```
678+
/// use std::mem;
679+
///
680+
/// fn read_usize(x: &[u8]) -> usize {
681+
/// assert!(x.len() >= mem::size_of::<usize>());
682+
///
683+
/// let ptr = x.as_ptr() as *const usize;
684+
///
685+
/// unsafe { ptr.read_unaligned() }
686+
/// }
687+
/// ```
672688
#[inline]
673689
#[stable(feature = "ptr_unaligned", since = "1.17.0")]
674690
pub unsafe fn read_unaligned<T>(src: *const T) -> T {
@@ -839,6 +855,22 @@ pub unsafe fn write<T>(dst: *mut T, src: T) {
839855
///
840856
/// Accessing unaligned fields directly with e.g. `packed.unaligned` is safe however.
841857
// FIXME: Update docs based on outcome of RFC #2582 and friends.
858+
///
859+
/// # Examples
860+
///
861+
/// Write an usize value to a byte buffer:
862+
///
863+
/// ```
864+
/// use std::mem;
865+
///
866+
/// fn write_usize(x: &mut [u8], val: usize) {
867+
/// assert!(x.len() >= mem::size_of::<usize>());
868+
///
869+
/// let ptr = x.as_mut_ptr() as *mut usize;
870+
///
871+
/// unsafe { ptr.write_unaligned(val) }
872+
/// }
873+
/// ```
842874
#[inline]
843875
#[stable(feature = "ptr_unaligned", since = "1.17.0")]
844876
pub unsafe fn write_unaligned<T>(dst: *mut T, src: T) {

src/librustc/hir/map/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1212,10 +1212,8 @@ impl<'a> print::State<'a> {
12121212
Node::Pat(a) => self.print_pat(&a),
12131213
Node::Arm(a) => self.print_arm(&a),
12141214
Node::Block(a) => {
1215-
use syntax::print::pprust::PrintState;
1216-
12171215
// containing cbox, will be closed by print-block at }
1218-
self.cbox(print::indent_unit);
1216+
self.cbox(print::INDENT_UNIT);
12191217
// head-ibox, will be closed by print-block after {
12201218
self.ibox(0);
12211219
self.print_block(&a)

0 commit comments

Comments
 (0)