diff options
Diffstat (limited to 'src/liballoc/vec.rs')
| -rw-r--r-- | src/liballoc/vec.rs | 79 |
1 files changed, 35 insertions, 44 deletions
diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index ba3b3dfbfc2..57e10498b92 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -63,18 +63,15 @@ use core::intrinsics::{arith_offset, assume}; use core::iter::{FromIterator, FusedIterator, TrustedLen}; use core::marker::PhantomData; use core::mem; +use core::ops::{self, Index, IndexMut, RangeBounds}; use core::ops::Bound::{Excluded, Included, Unbounded}; -use core::ops::{Index, IndexMut, RangeBounds}; -use core::ops; -use core::ptr; -use core::ptr::NonNull; -use core::slice; - -use collections::CollectionAllocErr; -use borrow::ToOwned; -use borrow::Cow; -use boxed::Box; -use raw_vec::RawVec; +use core::ptr::{self, NonNull}; +use core::slice::{self, SliceIndex}; + +use crate::borrow::{ToOwned, Cow}; +use crate::collections::CollectionAllocErr; +use crate::boxed::Box; +use crate::raw_vec::RawVec; /// A contiguous growable array type, written `Vec<T>` but pronounced 'vector'. /// @@ -1118,7 +1115,7 @@ impl<T> Vec<T> { /// assert_eq!(v, &[]); /// ``` #[stable(feature = "drain", since = "1.6.0")] - pub fn drain<R>(&mut self, range: R) -> Drain<T> + pub fn drain<R>(&mut self, range: R) -> Drain<'_, T> where R: RangeBounds<usize> { // Memory safety @@ -1477,7 +1474,7 @@ impl<'a> SetLenOnDrop<'a> { } } -impl<'a> Drop for SetLenOnDrop<'a> { +impl Drop for SetLenOnDrop<'_> { #[inline] fn drop(&mut self) { *self.len = self.local_len; @@ -1646,7 +1643,7 @@ impl<T: Clone> Clone for Vec<T> { // NB see the slice::hack module in slice.rs for more information #[cfg(test)] fn clone(&self) -> Vec<T> { - ::slice::to_vec(&**self) + crate::slice::to_vec(&**self) } fn clone_from(&mut self, other: &Vec<T>) { @@ -1667,10 +1664,7 @@ impl<T: Hash> Hash for Vec<T> { message="vector indices are of type `usize` or ranges of `usize`", label="vector indices are of type `usize` or ranges of `usize`", )] -impl<T, I> Index<I> for Vec<T> -where - I: ::core::slice::SliceIndex<[T]>, -{ +impl<T, I: SliceIndex<[T]>> Index<I> for Vec<T> { type Output = I::Output; #[inline] @@ -1684,10 +1678,7 @@ where message="vector indices are of type `usize` or ranges of `usize`", label="vector indices are of type `usize` or ranges of `usize`", )] -impl<T, I> IndexMut<I> for Vec<T> -where - I: ::core::slice::SliceIndex<[T]>, -{ +impl<T, I: SliceIndex<[T]>> IndexMut<I> for Vec<T> { #[inline] fn index_mut(&mut self, index: I) -> &mut Self::Output { IndexMut::index_mut(&mut **self, index) @@ -1981,7 +1972,7 @@ impl<T> Vec<T> { /// ``` #[inline] #[stable(feature = "vec_splice", since = "1.21.0")] - pub fn splice<R, I>(&mut self, range: R, replace_with: I) -> Splice<I::IntoIter> + pub fn splice<R, I>(&mut self, range: R, replace_with: I) -> Splice<'_, I::IntoIter> where R: RangeBounds<usize>, I: IntoIterator<Item=T> { Splice { @@ -2036,7 +2027,7 @@ impl<T> Vec<T> { /// assert_eq!(odds, vec![1, 3, 5, 9, 11, 13, 15]); /// ``` #[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")] - pub fn drain_filter<F>(&mut self, filter: F) -> DrainFilter<T, F> + pub fn drain_filter<F>(&mut self, filter: F) -> DrainFilter<'_, T, F> where F: FnMut(&mut T) -> bool, { let old_len = self.len(); @@ -2152,7 +2143,7 @@ impl<T> Default for Vec<T> { #[stable(feature = "rust1", since = "1.0.0")] impl<T: fmt::Debug> fmt::Debug for Vec<T> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(&**self, f) } } @@ -2193,7 +2184,7 @@ impl<'a, T: Clone> From<&'a [T]> for Vec<T> { } #[cfg(test)] fn from(s: &'a [T]) -> Vec<T> { - ::slice::to_vec(s) + crate::slice::to_vec(s) } } @@ -2205,7 +2196,7 @@ impl<'a, T: Clone> From<&'a mut [T]> for Vec<T> { } #[cfg(test)] fn from(s: &'a mut [T]) -> Vec<T> { - ::slice::to_vec(s) + crate::slice::to_vec(s) } } @@ -2295,7 +2286,7 @@ pub struct IntoIter<T> { #[stable(feature = "vec_intoiter_debug", since = "1.13.0")] impl<T: fmt::Debug> fmt::Debug for IntoIter<T> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("IntoIter") .field(&self.as_slice()) .finish() @@ -2465,7 +2456,7 @@ pub struct Drain<'a, T: 'a> { #[stable(feature = "collection_debug", since = "1.17.0")] impl<'a, T: 'a + fmt::Debug> fmt::Debug for Drain<'a, T> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("Drain") .field(&self.iter.as_slice()) .finish() @@ -2473,12 +2464,12 @@ impl<'a, T: 'a + fmt::Debug> fmt::Debug for Drain<'a, T> { } #[stable(feature = "drain", since = "1.6.0")] -unsafe impl<'a, T: Sync> Sync for Drain<'a, T> {} +unsafe impl<T: Sync> Sync for Drain<'_, T> {} #[stable(feature = "drain", since = "1.6.0")] -unsafe impl<'a, T: Send> Send for Drain<'a, T> {} +unsafe impl<T: Send> Send for Drain<'_, T> {} #[stable(feature = "drain", since = "1.6.0")] -impl<'a, T> Iterator for Drain<'a, T> { +impl<T> Iterator for Drain<'_, T> { type Item = T; #[inline] @@ -2492,7 +2483,7 @@ impl<'a, T> Iterator for Drain<'a, T> { } #[stable(feature = "drain", since = "1.6.0")] -impl<'a, T> DoubleEndedIterator for Drain<'a, T> { +impl<T> DoubleEndedIterator for Drain<'_, T> { #[inline] fn next_back(&mut self) -> Option<T> { self.iter.next_back().map(|elt| unsafe { ptr::read(elt as *const _) }) @@ -2500,7 +2491,7 @@ impl<'a, T> DoubleEndedIterator for Drain<'a, T> { } #[stable(feature = "drain", since = "1.6.0")] -impl<'a, T> Drop for Drain<'a, T> { +impl<T> Drop for Drain<'_, T> { fn drop(&mut self) { // exhaust self first self.for_each(drop); @@ -2524,14 +2515,14 @@ impl<'a, T> Drop for Drain<'a, T> { #[stable(feature = "drain", since = "1.6.0")] -impl<'a, T> ExactSizeIterator for Drain<'a, T> { +impl<T> ExactSizeIterator for Drain<'_, T> { fn is_empty(&self) -> bool { self.iter.is_empty() } } #[stable(feature = "fused", since = "1.26.0")] -impl<'a, T> FusedIterator for Drain<'a, T> {} +impl<T> FusedIterator for Drain<'_, T> {} /// A splicing iterator for `Vec`. /// @@ -2548,7 +2539,7 @@ pub struct Splice<'a, I: Iterator + 'a> { } #[stable(feature = "vec_splice", since = "1.21.0")] -impl<'a, I: Iterator> Iterator for Splice<'a, I> { +impl<I: Iterator> Iterator for Splice<'_, I> { type Item = I::Item; fn next(&mut self) -> Option<Self::Item> { @@ -2561,18 +2552,18 @@ impl<'a, I: Iterator> Iterator for Splice<'a, I> { } #[stable(feature = "vec_splice", since = "1.21.0")] -impl<'a, I: Iterator> DoubleEndedIterator for Splice<'a, I> { +impl<I: Iterator> DoubleEndedIterator for Splice<'_, I> { fn next_back(&mut self) -> Option<Self::Item> { self.drain.next_back() } } #[stable(feature = "vec_splice", since = "1.21.0")] -impl<'a, I: Iterator> ExactSizeIterator for Splice<'a, I> {} +impl<I: Iterator> ExactSizeIterator for Splice<'_, I> {} #[stable(feature = "vec_splice", since = "1.21.0")] -impl<'a, I: Iterator> Drop for Splice<'a, I> { +impl<I: Iterator> Drop for Splice<'_, I> { fn drop(&mut self) { self.drain.by_ref().for_each(drop); @@ -2613,7 +2604,7 @@ impl<'a, I: Iterator> Drop for Splice<'a, I> { } /// Private helper methods for `Splice::drop` -impl<'a, T> Drain<'a, T> { +impl<T> Drain<'_, T> { /// The range from `self.vec.len` to `self.tail_start` contains elements /// that have been moved out. /// Fill that range as much as possible with new elements from the `replace_with` iterator. @@ -2654,7 +2645,7 @@ impl<'a, T> Drain<'a, T> { /// An iterator produced by calling `drain_filter` on Vec. #[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")] #[derive(Debug)] -pub struct DrainFilter<'a, T: 'a, F> +pub struct DrainFilter<'a, T, F> where F: FnMut(&mut T) -> bool, { vec: &'a mut Vec<T>, @@ -2665,7 +2656,7 @@ pub struct DrainFilter<'a, T: 'a, F> } #[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")] -impl<'a, T, F> Iterator for DrainFilter<'a, T, F> +impl<T, F> Iterator for DrainFilter<'_, T, F> where F: FnMut(&mut T) -> bool, { type Item = T; @@ -2699,7 +2690,7 @@ impl<'a, T, F> Iterator for DrainFilter<'a, T, F> } #[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")] -impl<'a, T, F> Drop for DrainFilter<'a, T, F> +impl<T, F> Drop for DrainFilter<'_, T, F> where F: FnMut(&mut T) -> bool, { fn drop(&mut self) { |
