From 301e457989ea80926a98f3279dc2e42da47e466d Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Mon, 1 Jan 2018 19:06:59 -0800 Subject: Fix panic condition docs for Vec::insert. Fixes https://github.com/rust-lang/rust/issues/47065. --- src/liballoc/vec.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/liballoc') diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 93d7e66b7b2..301e44632b8 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -715,7 +715,7 @@ impl Vec { /// /// # Panics /// - /// Panics if `index` is out of bounds. + /// Panics if `index > len`. /// /// # Examples /// -- cgit 1.4.1-3-g733a5 From 9957cf60232d05db250e6c3b89210850bc7b1839 Mon Sep 17 00:00:00 2001 From: Sebastian Dröge Date: Tue, 2 Jan 2018 01:46:50 +0200 Subject: Consistently use chunk_size as the field name for Chunks and ChunksMut Previously Chunks used size and ChunksMut used chunk_size --- src/liballoc/slice.rs | 12 ++++++------ src/libcore/slice/mod.rs | 30 +++++++++++++++--------------- 2 files changed, 21 insertions(+), 21 deletions(-) (limited to 'src/liballoc') diff --git a/src/liballoc/slice.rs b/src/liballoc/slice.rs index ab574c9f7e7..b880616833a 100644 --- a/src/liballoc/slice.rs +++ b/src/liballoc/slice.rs @@ -606,14 +606,14 @@ impl [T] { core_slice::SliceExt::windows(self, size) } - /// Returns an iterator over `size` elements of the slice at a - /// time. The chunks are slices and do not overlap. If `size` does + /// 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 chunk will - /// not have length `size`. + /// not have length `chunk_size`. /// /// # Panics /// - /// Panics if `size` is 0. + /// Panics if `chunk_size` is 0. /// /// # Examples /// @@ -627,8 +627,8 @@ impl [T] { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn chunks(&self, size: usize) -> Chunks { - core_slice::SliceExt::chunks(self, size) + pub fn chunks(&self, chunk_size: usize) -> Chunks { + core_slice::SliceExt::chunks(self, chunk_size) } /// Returns an iterator over `chunk_size` elements of the slice at a time. diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index 20d586a4021..817e309cf77 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -348,9 +348,9 @@ impl SliceExt for [T] { } #[inline] - fn chunks(&self, size: usize) -> Chunks { - assert!(size != 0); - Chunks { v: self, size: size } + fn chunks(&self, chunk_size: usize) -> Chunks { + assert!(chunk_size != 0); + Chunks { v: self, chunk_size: chunk_size } } #[inline] @@ -2117,7 +2117,7 @@ impl<'a, T> ExactSizeIterator for Windows<'a, T> {} #[unstable(feature = "fused", issue = "35602")] impl<'a, T> FusedIterator for Windows<'a, T> {} -/// An iterator over a slice in (non-overlapping) chunks (`size` elements at a +/// An iterator over a slice in (non-overlapping) chunks (`chunk_size` elements at a /// time). /// /// When the slice len is not evenly divided by the chunk size, the last slice @@ -2131,7 +2131,7 @@ impl<'a, T> FusedIterator for Windows<'a, T> {} #[stable(feature = "rust1", since = "1.0.0")] pub struct Chunks<'a, T:'a> { v: &'a [T], - size: usize + chunk_size: usize } // FIXME(#26925) Remove in favor of `#[derive(Clone)]` @@ -2140,7 +2140,7 @@ impl<'a, T> Clone for Chunks<'a, T> { fn clone(&self) -> Chunks<'a, T> { Chunks { v: self.v, - size: self.size, + chunk_size: self.chunk_size, } } } @@ -2154,7 +2154,7 @@ impl<'a, T> Iterator for Chunks<'a, T> { if self.v.is_empty() { None } else { - let chunksz = cmp::min(self.v.len(), self.size); + let chunksz = cmp::min(self.v.len(), self.chunk_size); let (fst, snd) = self.v.split_at(chunksz); self.v = snd; Some(fst) @@ -2166,8 +2166,8 @@ impl<'a, T> Iterator for Chunks<'a, T> { if self.v.is_empty() { (0, Some(0)) } else { - let n = self.v.len() / self.size; - let rem = self.v.len() % self.size; + let n = self.v.len() / self.chunk_size; + let rem = self.v.len() % self.chunk_size; let n = if rem > 0 { n+1 } else { n }; (n, Some(n)) } @@ -2180,12 +2180,12 @@ impl<'a, T> Iterator for Chunks<'a, T> { #[inline] fn nth(&mut self, n: usize) -> Option { - let (start, overflow) = n.overflowing_mul(self.size); + let (start, overflow) = n.overflowing_mul(self.chunk_size); if start >= self.v.len() || overflow { self.v = &[]; None } else { - let end = match start.checked_add(self.size) { + let end = match start.checked_add(self.chunk_size) { Some(sum) => cmp::min(self.v.len(), sum), None => self.v.len(), }; @@ -2200,7 +2200,7 @@ impl<'a, T> Iterator for Chunks<'a, T> { if self.v.is_empty() { None } else { - let start = (self.v.len() - 1) / self.size * self.size; + let start = (self.v.len() - 1) / self.chunk_size * self.chunk_size; Some(&self.v[start..]) } } @@ -2213,8 +2213,8 @@ impl<'a, T> DoubleEndedIterator for Chunks<'a, T> { if self.v.is_empty() { None } else { - let remainder = self.v.len() % self.size; - let chunksz = if remainder != 0 { remainder } else { self.size }; + let remainder = self.v.len() % self.chunk_size; + let chunksz = if remainder != 0 { remainder } else { self.chunk_size }; let (fst, snd) = self.v.split_at(self.v.len() - chunksz); self.v = fst; Some(snd) @@ -2228,7 +2228,7 @@ impl<'a, T> ExactSizeIterator for Chunks<'a, T> {} #[unstable(feature = "fused", issue = "35602")] impl<'a, T> FusedIterator for Chunks<'a, T> {} -/// An iterator over a slice in (non-overlapping) mutable chunks (`size` +/// An iterator over a slice in (non-overlapping) mutable chunks (`chunk_size` /// elements at a time). When the slice len is not evenly divided by the chunk /// size, the last slice of the iteration will be the remainder. /// -- cgit 1.4.1-3-g733a5 From d5acd235658bd8d52db53aa10452620642b715dc Mon Sep 17 00:00:00 2001 From: David Ross Date: Mon, 1 Jan 2018 19:14:32 -0800 Subject: Mention SliceConcatExt's stability in its docs SliceConcatExt's status as an unstable trait with stable methods is documented in the compiler error for using it, and in https://doc.rust-lang.org/std/prelude/, but it is not mentioned in the trait itself. Mentioning the methods can be used in stable rust today should help users who are looking for a `join` method while working on stable rust. --- src/liballoc/slice.rs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/liballoc') diff --git a/src/liballoc/slice.rs b/src/liballoc/slice.rs index ab574c9f7e7..fecea3339d2 100644 --- a/src/liballoc/slice.rs +++ b/src/liballoc/slice.rs @@ -1725,6 +1725,14 @@ impl [u8] { reason = "trait should not have to exist", issue = "27747")] /// An extension trait for concatenating slices +/// +/// While this trait is unstable, the methods are stable. `SliceConcatExt` is +/// included in the [standard library prelude], so you can use [`join()`] and +/// [`concat()`] as if they existed on `[T]` itself. +/// +/// [standard library prelude]: ../../std/prelude/index.html +/// [`join()`]: #tymethod.join +/// [`concat()`]: #tymethod.concat pub trait SliceConcatExt { #[unstable(feature = "slice_concat_ext", reason = "trait should not have to exist", -- cgit 1.4.1-3-g733a5