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 #47445

Merged
merged 32 commits into from
Jan 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
0eba4c2
doc: show that `f32::log` and `f64::log` are not correctly rounded
tspiteri Jan 8, 2018
6d82e78
remove implementation detail from doc
tspiteri Jan 9, 2018
76cf279
Add NLL tests for #46557 and #38899
chrisvittal Jan 11, 2018
d088b25
Avoid panicking when invalid argument is passed to cfg(..)
topecongiro Jan 12, 2018
e14720b
remove unnecessary compile-flags comments
chrisvittal Jan 12, 2018
cee295e
fix off-by-one error
bmusin Jan 10, 2018
51d546f
Add slice::ExactChunks and ::ExactChunksMut iterators
sdroege Jan 2, 2018
83396fc
Add #![feature(exact_chunks)] to the documentation examples to fix th…
sdroege Jan 2, 2018
802ba9e
Fix assertions in examples of the exact_chunk() documentation
sdroege Jan 2, 2018
e51a89a
Fix doctests for slice::exact_chunks() for real
sdroege Jan 2, 2018
aa0c08a
Apply review comments from @bluss
sdroege Jan 2, 2018
cea36f4
Remove useless assertion
sdroege Jan 2, 2018
6bf1dfd
Implement TrustedRandomAccess for slice::{ExactChunks, ExactChunksMut}
sdroege Jan 2, 2018
8a82e8e
Mention in the exact_chunks docs that this can often be optimized bet…
sdroege Jan 9, 2018
baa81dc
Use assert_eq!() instead of assert!(a == b) in slice chunks_mut() uni…
sdroege Jan 11, 2018
ed77483
Test the whole chunks instead of just an element in the chunks/chunks…
sdroege Jan 11, 2018
5f4fc82
Add unit tests for exact_chunks/exact_chunks_mut
sdroege Jan 11, 2018
38e2667
Enforce dashes in the unstable book file names
est31 Jan 13, 2018
52e074e
Better Debug impl for io::Error.
clarfonthey Jan 2, 2018
318cf22
Move "no asm" check into AST validation
petrochenkov Jan 13, 2018
46c59ae
Make ui-fulldeps/update-references executable
etaoins Jan 14, 2018
1482afb
Remove leftover Rand stuff
FenrirWolf Jan 15, 2018
06112ab
Rollup merge of #47120 - clarcharr:io_error_debug, r=dtolnay
kennytm Jan 15, 2018
5d0474a
Rollup merge of #47126 - sdroege:exact-chunks, r=bluss
kennytm Jan 15, 2018
26c1ec3
Rollup merge of #47277 - tspiteri:log-correctness, r=frewsxcv
kennytm Jan 15, 2018
6966f33
Rollup merge of #47330 - bmusin:patch-2, r=shepmaster
kennytm Jan 15, 2018
afb1e19
Rollup merge of #47368 - chrisvittal:nll-tests, r=nikomatsakis
kennytm Jan 15, 2018
f98a9a6
Rollup merge of #47372 - topecongiro:issue-43925, r=alexcrichton
kennytm Jan 15, 2018
63f4285
Rollup merge of #47414 - est31:master, r=alexcrichton
kennytm Jan 15, 2018
2dc815c
Rollup merge of #47417 - petrochenkov:noasm, r=estebank
kennytm Jan 15, 2018
5d9d5ea
Rollup merge of #47432 - etaoins:make-fulldeps-update-references-exec…
kennytm Jan 15, 2018
fa008c0
Rollup merge of #47443 - FenrirWolf:rand, r=alexcrichton
kennytm Jan 15, 2018
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
1 change: 1 addition & 0 deletions src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
#![feature(unsize)]
#![feature(allocator_internals)]
#![feature(on_unimplemented)]
#![feature(exact_chunks)]

#![cfg_attr(not(test), feature(fused, fn_traits, placement_new_protocol, swap_with_slice, i128))]
#![cfg_attr(test, feature(test, box_heap))]
Expand Down
74 changes: 74 additions & 0 deletions src/liballoc/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ pub use core::slice::{from_raw_parts, from_raw_parts_mut};
pub use core::slice::{from_ref, from_ref_mut};
#[unstable(feature = "slice_get_slice", issue = "35729")]
pub use core::slice::SliceIndex;
#[unstable(feature = "exact_chunks", issue = "47115")]
pub use core::slice::{ExactChunks, ExactChunksMut};

////////////////////////////////////////////////////////////////////////////////
// Basic slice extension methods
Expand Down Expand Up @@ -611,6 +613,9 @@ impl<T> [T] {
/// not divide the length of the slice, then the last chunk will
/// not have length `chunk_size`.
///
/// See [`exact_chunks`] for a variant of this iterator that returns chunks
/// of always exactly `chunk_size` elements.
///
/// # Panics
///
/// Panics if `chunk_size` is 0.
Expand All @@ -631,11 +636,44 @@ impl<T> [T] {
core_slice::SliceExt::chunks(self, chunk_size)
}

/// Returns an iterator over `chunk_size` elements of the slice at a
/// time. The chunks are slices and do not overlap. If `chunk_size` does
/// not divide the length of the slice, then the last up to `chunk_size-1`
/// elements will be omitted.
///
/// Due to each chunk having exactly `chunk_size` elements, the compiler
/// can often optimize the resulting code better than in the case of
/// [`chunks`].
///
/// # Panics
///
/// Panics if `chunk_size` is 0.
///
/// # Examples
///
/// ```
/// #![feature(exact_chunks)]
///
/// let slice = ['l', 'o', 'r', 'e', 'm'];
/// let mut iter = slice.exact_chunks(2);
/// assert_eq!(iter.next().unwrap(), &['l', 'o']);
/// assert_eq!(iter.next().unwrap(), &['r', 'e']);
/// assert!(iter.next().is_none());
/// ```
#[unstable(feature = "exact_chunks", issue = "47115")]
#[inline]
pub fn exact_chunks(&self, chunk_size: usize) -> ExactChunks<T> {
core_slice::SliceExt::exact_chunks(self, chunk_size)
}

/// Returns an iterator over `chunk_size` elements of the slice at a time.
/// The chunks are mutable slices, and do not overlap. If `chunk_size` does
/// not divide the length of the slice, then the last chunk will not
/// have length `chunk_size`.
///
/// See [`exact_chunks_mut`] for a variant of this iterator that returns chunks
/// of always exactly `chunk_size` elements.
///
/// # Panics
///
/// Panics if `chunk_size` is 0.
Expand All @@ -660,6 +698,42 @@ impl<T> [T] {
core_slice::SliceExt::chunks_mut(self, chunk_size)
}

/// Returns an iterator over `chunk_size` elements of the slice at a time.
/// The chunks are mutable slices, and do not overlap. If `chunk_size` does
/// not divide the length of the slice, then the last up to `chunk_size-1`
/// elements will be omitted.
///
///
/// Due to each chunk having exactly `chunk_size` elements, the compiler
/// can often optimize the resulting code better than in the case of
/// [`chunks_mut`].
///
/// # Panics
///
/// Panics if `chunk_size` is 0.
///
/// # Examples
///
/// ```
/// #![feature(exact_chunks)]
///
/// let v = &mut [0, 0, 0, 0, 0];
/// let mut count = 1;
///
/// for chunk in v.exact_chunks_mut(2) {
/// for elem in chunk.iter_mut() {
/// *elem += count;
/// }
/// count += 1;
/// }
/// assert_eq!(v, &[1, 1, 2, 2, 0]);
/// ```
#[unstable(feature = "exact_chunks", issue = "47115")]
#[inline]
pub fn exact_chunks_mut(&mut self, chunk_size: usize) -> ExactChunksMut<T> {
core_slice::SliceExt::exact_chunks_mut(self, chunk_size)
}

/// Divides one slice into two at an index.
///
/// The first will contain all indices from `[0, mid)` (excluding
Expand Down
1 change: 1 addition & 0 deletions src/liballoc/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#![feature(string_retain)]
#![feature(unboxed_closures)]
#![feature(unicode)]
#![feature(exact_chunks)]

extern crate alloc_system;
extern crate std_unicode;
Expand Down
60 changes: 58 additions & 2 deletions src/liballoc/tests/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,30 @@ fn test_chunksator_0() {
let _it = v.chunks(0);
}

#[test]
fn test_exact_chunksator() {
let v = &[1, 2, 3, 4, 5];

assert_eq!(v.exact_chunks(2).len(), 2);

let chunks: &[&[_]] = &[&[1, 2], &[3, 4]];
assert_eq!(v.exact_chunks(2).collect::<Vec<_>>(), chunks);
let chunks: &[&[_]] = &[&[1, 2, 3]];
assert_eq!(v.exact_chunks(3).collect::<Vec<_>>(), chunks);
let chunks: &[&[_]] = &[];
assert_eq!(v.exact_chunks(6).collect::<Vec<_>>(), chunks);

let chunks: &[&[_]] = &[&[3, 4], &[1, 2]];
assert_eq!(v.exact_chunks(2).rev().collect::<Vec<_>>(), chunks);
}

#[test]
#[should_panic]
fn test_exact_chunksator_0() {
let v = &[1, 2, 3, 4];
let _it = v.exact_chunks(0);
}

#[test]
fn test_reverse_part() {
let mut values = [1, 2, 3, 4, 5];
Expand Down Expand Up @@ -1159,7 +1183,7 @@ fn test_mut_chunks() {
}
}
let result = [0, 0, 0, 1, 1, 1, 2];
assert!(v == result);
assert_eq!(v, result);
}

#[test]
Expand All @@ -1171,7 +1195,7 @@ fn test_mut_chunks_rev() {
}
}
let result = [2, 2, 2, 1, 1, 1, 0];
assert!(v == result);
assert_eq!(v, result);
}

#[test]
Expand All @@ -1181,6 +1205,38 @@ fn test_mut_chunks_0() {
let _it = v.chunks_mut(0);
}

#[test]
fn test_mut_exact_chunks() {
let mut v = [0, 1, 2, 3, 4, 5, 6];
assert_eq!(v.exact_chunks_mut(2).len(), 3);
for (i, chunk) in v.exact_chunks_mut(3).enumerate() {
for x in chunk {
*x = i as u8;
}
}
let result = [0, 0, 0, 1, 1, 1, 6];
assert_eq!(v, result);
}

#[test]
fn test_mut_exact_chunks_rev() {
let mut v = [0, 1, 2, 3, 4, 5, 6];
for (i, chunk) in v.exact_chunks_mut(3).rev().enumerate() {
for x in chunk {
*x = i as u8;
}
}
let result = [1, 1, 1, 0, 0, 0, 6];
assert_eq!(v, result);
}

#[test]
#[should_panic]
fn test_mut_exact_chunks_0() {
let mut v = [1, 2, 3, 4];
let _it = v.exact_chunks_mut(0);
}

#[test]
fn test_mut_last() {
let mut x = [1, 2, 3, 4, 5];
Expand Down
Loading