X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibcore%2Fslice%2Fmod.rs;h=76dcca0257817b6f6917345345827a69cf45ba83;hb=ef5c00d0ca027f8ef4b41fecd53177e105daa6a8;hp=d400bd49050a965835578b59a52da87ffd5b37a5;hpb=de3d640f59c4fa4a09faf2a8d6b0a812aaa6d6cb;p=rust.git diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index d400bd49050..76dcca02578 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -1175,9 +1175,10 @@ pub fn ends_with(&self, needle: &[T]) -> bool /// Binary searches this sorted slice for a given element. /// - /// If the value is found then `Ok` is returned, containing the - /// index of the matching element; if the value is not found then - /// `Err` is returned, containing the index where a matching + /// If the value is found then [`Result::Ok`] is returned, containing the + /// index of the matching element. If there are multiple matches, then any + /// one of the matches could be returned. If the value is not found then + /// [`Result::Err`] is returned, containing the index where a matching /// element could be inserted while maintaining sorted order. /// /// # Examples @@ -1209,9 +1210,10 @@ pub fn binary_search(&self, x: &T) -> Result /// order code that indicates whether its argument is `Less`, /// `Equal` or `Greater` the desired target. /// - /// If a matching value is found then returns `Ok`, containing - /// the index for the matched element; if no match is found then - /// `Err` is returned, containing the index where a matching + /// If the value is found then [`Result::Ok`] is returned, containing the + /// index of the matching element. If there are multiple matches, then any + /// one of the matches could be returned. If the value is not found then + /// [`Result::Err`] is returned, containing the index where a matching /// element could be inserted while maintaining sorted order. /// /// # Examples @@ -1265,10 +1267,11 @@ pub fn binary_search_by<'a, F>(&'a self, mut f: F) -> Result /// Assumes that the slice is sorted by the key, for instance with /// [`sort_by_key`] using the same key extraction function. /// - /// If a matching value is found then returns `Ok`, containing the - /// index for the matched element; if no match is found then `Err` - /// is returned, containing the index where a matching element could - /// be inserted while maintaining sorted order. + /// If the value is found then [`Result::Ok`] is returned, containing the + /// index of the matching element. If there are multiple matches, then any + /// one of the matches could be returned. If the value is not found then + /// [`Result::Err`] is returned, containing the index where a matching + /// element could be inserted while maintaining sorted order. /// /// [`sort_by_key`]: #method.sort_by_key /// @@ -2529,15 +2532,15 @@ fn index_mut(self, slice: &mut [T]) -> &mut [T] { //////////////////////////////////////////////////////////////////////////////// #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T> Default for &'a [T] { +impl Default for &[T] { /// Creates an empty slice. - fn default() -> &'a [T] { &[] } + fn default() -> Self { &[] } } #[stable(feature = "mut_slice_default", since = "1.5.0")] -impl<'a, T> Default for &'a mut [T] { +impl Default for &mut [T] { /// Creates a mutable empty slice. - fn default() -> &'a mut [T] { &mut [] } + fn default() -> Self { &mut [] } } // @@ -2864,7 +2867,7 @@ pub struct Iter<'a, T: 'a> { } #[stable(feature = "core_impl_debug", since = "1.9.0")] -impl<'a, T: 'a + fmt::Debug> fmt::Debug for Iter<'a, T> { +impl fmt::Debug for Iter<'_, T> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_tuple("Iter") .field(&self.as_slice()) @@ -2873,9 +2876,9 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { } #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl<'a, T: Sync> Sync for Iter<'a, T> {} +unsafe impl Sync for Iter<'_, T> {} #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl<'a, T: Sync> Send for Iter<'a, T> {} +unsafe impl Send for Iter<'_, T> {} impl<'a, T> Iter<'a, T> { /// View the underlying data as a subslice of the original data. @@ -2911,12 +2914,12 @@ pub fn as_slice(&self) -> &'a [T] { iterator!{struct Iter -> *const T, &'a T, const, /* no mut */} #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T> Clone for Iter<'a, T> { - fn clone(&self) -> Iter<'a, T> { Iter { ptr: self.ptr, end: self.end, _marker: self._marker } } +impl Clone for Iter<'_, T> { + fn clone(&self) -> Self { Iter { ptr: self.ptr, end: self.end, _marker: self._marker } } } #[stable(feature = "slice_iter_as_ref", since = "1.13.0")] -impl<'a, T> AsRef<[T]> for Iter<'a, T> { +impl AsRef<[T]> for Iter<'_, T> { fn as_ref(&self) -> &[T] { self.as_slice() } @@ -2956,7 +2959,7 @@ pub struct IterMut<'a, T: 'a> { } #[stable(feature = "core_impl_debug", since = "1.9.0")] -impl<'a, T: 'a + fmt::Debug> fmt::Debug for IterMut<'a, T> { +impl fmt::Debug for IterMut<'_, T> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_tuple("IterMut") .field(&self.make_slice()) @@ -2965,9 +2968,9 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { } #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl<'a, T: Sync> Sync for IterMut<'a, T> {} +unsafe impl Sync for IterMut<'_, T> {} #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl<'a, T: Send> Send for IterMut<'a, T> {} +unsafe impl Send for IterMut<'_, T> {} impl<'a, T> IterMut<'a, T> { /// View the underlying data as a subslice of the original data. @@ -3035,7 +3038,7 @@ pub struct Split<'a, T:'a, P> where P: FnMut(&T) -> bool { } #[stable(feature = "core_impl_debug", since = "1.9.0")] -impl<'a, T: 'a + fmt::Debug, P> fmt::Debug for Split<'a, T, P> where P: FnMut(&T) -> bool { +impl fmt::Debug for Split<'_, T, P> where P: FnMut(&T) -> bool { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("Split") .field("v", &self.v) @@ -3046,8 +3049,8 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { // FIXME(#26925) Remove in favor of `#[derive(Clone)]` #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T, P> Clone for Split<'a, T, P> where P: Clone + FnMut(&T) -> bool { - fn clone(&self) -> Split<'a, T, P> { +impl Clone for Split<'_, T, P> where P: Clone + FnMut(&T) -> bool { + fn clone(&self) -> Self { Split { v: self.v, pred: self.pred.clone(), @@ -3109,7 +3112,7 @@ fn finish(&mut self) -> Option<&'a [T]> { } #[stable(feature = "fused", since = "1.26.0")] -impl<'a, T, P> FusedIterator for Split<'a, T, P> where P: FnMut(&T) -> bool {} +impl FusedIterator for Split<'_, T, P> where P: FnMut(&T) -> bool {} /// An iterator over the subslices of the vector which are separated /// by elements that match `pred`. @@ -3126,7 +3129,7 @@ pub struct SplitMut<'a, T:'a, P> where P: FnMut(&T) -> bool { } #[stable(feature = "core_impl_debug", since = "1.9.0")] -impl<'a, T: 'a + fmt::Debug, P> fmt::Debug for SplitMut<'a, T, P> where P: FnMut(&T) -> bool { +impl fmt::Debug for SplitMut<'_, T, P> where P: FnMut(&T) -> bool { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("SplitMut") .field("v", &self.v) @@ -3207,7 +3210,7 @@ fn next_back(&mut self) -> Option<&'a mut [T]> { } #[stable(feature = "fused", since = "1.26.0")] -impl<'a, T, P> FusedIterator for SplitMut<'a, T, P> where P: FnMut(&T) -> bool {} +impl FusedIterator for SplitMut<'_, T, P> where P: FnMut(&T) -> bool {} /// An iterator over subslices separated by elements that match a predicate /// function, starting from the end of the slice. @@ -3223,7 +3226,7 @@ pub struct RSplit<'a, T:'a, P> where P: FnMut(&T) -> bool { } #[stable(feature = "slice_rsplit", since = "1.27.0")] -impl<'a, T: 'a + fmt::Debug, P> fmt::Debug for RSplit<'a, T, P> where P: FnMut(&T) -> bool { +impl fmt::Debug for RSplit<'_, T, P> where P: FnMut(&T) -> bool { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("RSplit") .field("v", &self.inner.v) @@ -3264,7 +3267,7 @@ fn finish(&mut self) -> Option<&'a [T]> { } #[stable(feature = "slice_rsplit", since = "1.27.0")] -impl<'a, T, P> FusedIterator for RSplit<'a, T, P> where P: FnMut(&T) -> bool {} +impl FusedIterator for RSplit<'_, T, P> where P: FnMut(&T) -> bool {} /// An iterator over the subslices of the vector which are separated /// by elements that match `pred`, starting from the end of the slice. @@ -3279,7 +3282,7 @@ pub struct RSplitMut<'a, T:'a, P> where P: FnMut(&T) -> bool { } #[stable(feature = "slice_rsplit", since = "1.27.0")] -impl<'a, T: 'a + fmt::Debug, P> fmt::Debug for RSplitMut<'a, T, P> where P: FnMut(&T) -> bool { +impl fmt::Debug for RSplitMut<'_, T, P> where P: FnMut(&T) -> bool { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("RSplitMut") .field("v", &self.inner.v) @@ -3322,7 +3325,7 @@ fn next_back(&mut self) -> Option<&'a mut [T]> { } #[stable(feature = "slice_rsplit", since = "1.27.0")] -impl<'a, T, P> FusedIterator for RSplitMut<'a, T, P> where P: FnMut(&T) -> bool {} +impl FusedIterator for RSplitMut<'_, T, P> where P: FnMut(&T) -> bool {} /// An private iterator over subslices separated by elements that /// match a predicate function, splitting at most a fixed number of @@ -3365,7 +3368,7 @@ pub struct SplitN<'a, T: 'a, P> where P: FnMut(&T) -> bool { } #[stable(feature = "core_impl_debug", since = "1.9.0")] -impl<'a, T: 'a + fmt::Debug, P> fmt::Debug for SplitN<'a, T, P> where P: FnMut(&T) -> bool { +impl fmt::Debug for SplitN<'_, T, P> where P: FnMut(&T) -> bool { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("SplitN") .field("inner", &self.inner) @@ -3387,7 +3390,7 @@ pub struct RSplitN<'a, T: 'a, P> where P: FnMut(&T) -> bool { } #[stable(feature = "core_impl_debug", since = "1.9.0")] -impl<'a, T: 'a + fmt::Debug, P> fmt::Debug for RSplitN<'a, T, P> where P: FnMut(&T) -> bool { +impl fmt::Debug for RSplitN<'_, T, P> where P: FnMut(&T) -> bool { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("RSplitN") .field("inner", &self.inner) @@ -3408,7 +3411,7 @@ pub struct SplitNMut<'a, T: 'a, P> where P: FnMut(&T) -> bool { } #[stable(feature = "core_impl_debug", since = "1.9.0")] -impl<'a, T: 'a + fmt::Debug, P> fmt::Debug for SplitNMut<'a, T, P> where P: FnMut(&T) -> bool { +impl fmt::Debug for SplitNMut<'_, T, P> where P: FnMut(&T) -> bool { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("SplitNMut") .field("inner", &self.inner) @@ -3430,7 +3433,7 @@ pub struct RSplitNMut<'a, T: 'a, P> where P: FnMut(&T) -> bool { } #[stable(feature = "core_impl_debug", since = "1.9.0")] -impl<'a, T: 'a + fmt::Debug, P> fmt::Debug for RSplitNMut<'a, T, P> where P: FnMut(&T) -> bool { +impl fmt::Debug for RSplitNMut<'_, T, P> where P: FnMut(&T) -> bool { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("RSplitNMut") .field("inner", &self.inner) @@ -3483,8 +3486,8 @@ pub struct Windows<'a, T:'a> { // FIXME(#26925) Remove in favor of `#[derive(Clone)]` #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T> Clone for Windows<'a, T> { - fn clone(&self) -> Windows<'a, T> { +impl Clone for Windows<'_, T> { + fn clone(&self) -> Self { Windows { v: self.v, size: self.size, @@ -3561,13 +3564,13 @@ fn next_back(&mut self) -> Option<&'a [T]> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T> ExactSizeIterator for Windows<'a, T> {} +impl ExactSizeIterator for Windows<'_, T> {} #[unstable(feature = "trusted_len", issue = "37572")] -unsafe impl<'a, T> TrustedLen for Windows<'a, T> {} +unsafe impl TrustedLen for Windows<'_, T> {} #[stable(feature = "fused", since = "1.26.0")] -impl<'a, T> FusedIterator for Windows<'a, T> {} +impl FusedIterator for Windows<'_, T> {} #[doc(hidden)] unsafe impl<'a, T> TrustedRandomAccess for Windows<'a, T> { @@ -3596,8 +3599,8 @@ pub struct Chunks<'a, T:'a> { // FIXME(#26925) Remove in favor of `#[derive(Clone)]` #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T> Clone for Chunks<'a, T> { - fn clone(&self) -> Chunks<'a, T> { +impl Clone for Chunks<'_, T> { + fn clone(&self) -> Self { Chunks { v: self.v, chunk_size: self.chunk_size, @@ -3683,13 +3686,13 @@ fn next_back(&mut self) -> Option<&'a [T]> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T> ExactSizeIterator for Chunks<'a, T> {} +impl ExactSizeIterator for Chunks<'_, T> {} #[unstable(feature = "trusted_len", issue = "37572")] -unsafe impl<'a, T> TrustedLen for Chunks<'a, T> {} +unsafe impl TrustedLen for Chunks<'_, T> {} #[stable(feature = "fused", since = "1.26.0")] -impl<'a, T> FusedIterator for Chunks<'a, T> {} +impl FusedIterator for Chunks<'_, T> {} #[doc(hidden)] unsafe impl<'a, T> TrustedRandomAccess for Chunks<'a, T> { @@ -3802,13 +3805,13 @@ fn next_back(&mut self) -> Option<&'a mut [T]> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T> ExactSizeIterator for ChunksMut<'a, T> {} +impl ExactSizeIterator for ChunksMut<'_, T> {} #[unstable(feature = "trusted_len", issue = "37572")] -unsafe impl<'a, T> TrustedLen for ChunksMut<'a, T> {} +unsafe impl TrustedLen for ChunksMut<'_, T> {} #[stable(feature = "fused", since = "1.26.0")] -impl<'a, T> FusedIterator for ChunksMut<'a, T> {} +impl FusedIterator for ChunksMut<'_, T> {} #[doc(hidden)] unsafe impl<'a, T> TrustedRandomAccess for ChunksMut<'a, T> { @@ -3855,8 +3858,8 @@ pub fn remainder(&self) -> &'a [T] { // FIXME(#26925) Remove in favor of `#[derive(Clone)]` #[unstable(feature = "chunks_exact", issue = "47115")] -impl<'a, T> Clone for ChunksExact<'a, T> { - fn clone(&self) -> ChunksExact<'a, T> { +impl Clone for ChunksExact<'_, T> { + fn clone(&self) -> Self { ChunksExact { v: self.v, rem: self.rem, @@ -3925,17 +3928,17 @@ fn next_back(&mut self) -> Option<&'a [T]> { } #[unstable(feature = "chunks_exact", issue = "47115")] -impl<'a, T> ExactSizeIterator for ChunksExact<'a, T> { +impl ExactSizeIterator for ChunksExact<'_, T> { fn is_empty(&self) -> bool { self.v.is_empty() } } #[unstable(feature = "trusted_len", issue = "37572")] -unsafe impl<'a, T> TrustedLen for ChunksExact<'a, T> {} +unsafe impl TrustedLen for ChunksExact<'_, T> {} #[unstable(feature = "chunks_exact", issue = "47115")] -impl<'a, T> FusedIterator for ChunksExact<'a, T> {} +impl FusedIterator for ChunksExact<'_, T> {} #[doc(hidden)] unsafe impl<'a, T> TrustedRandomAccess for ChunksExact<'a, T> { @@ -4040,17 +4043,17 @@ fn next_back(&mut self) -> Option<&'a mut [T]> { } #[unstable(feature = "chunks_exact", issue = "47115")] -impl<'a, T> ExactSizeIterator for ChunksExactMut<'a, T> { +impl ExactSizeIterator for ChunksExactMut<'_, T> { fn is_empty(&self) -> bool { self.v.is_empty() } } #[unstable(feature = "trusted_len", issue = "37572")] -unsafe impl<'a, T> TrustedLen for ChunksExactMut<'a, T> {} +unsafe impl TrustedLen for ChunksExactMut<'_, T> {} #[unstable(feature = "chunks_exact", issue = "47115")] -impl<'a, T> FusedIterator for ChunksExactMut<'a, T> {} +impl FusedIterator for ChunksExactMut<'_, T> {} #[doc(hidden)] unsafe impl<'a, T> TrustedRandomAccess for ChunksExactMut<'a, T> {