diff options
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/collections/hash/map.rs | 66 | ||||
| -rw-r--r-- | src/libstd/collections/hash/set.rs | 48 | ||||
| -rw-r--r-- | src/libstd/collections/hash/table.rs | 32 | ||||
| -rw-r--r-- | src/libstd/env.rs | 2 | ||||
| -rw-r--r-- | src/libstd/ffi/c_str.rs | 4 | ||||
| -rw-r--r-- | src/libstd/ffi/os_str.rs | 4 | ||||
| -rw-r--r-- | src/libstd/fs.rs | 33 | ||||
| -rw-r--r-- | src/libstd/io/buffered.rs | 2 | ||||
| -rw-r--r-- | src/libstd/io/cursor.rs | 4 | ||||
| -rw-r--r-- | src/libstd/io/impls.rs | 14 | ||||
| -rw-r--r-- | src/libstd/io/mod.rs | 4 | ||||
| -rw-r--r-- | src/libstd/io/stdio.rs | 14 | ||||
| -rw-r--r-- | src/libstd/net/addr.rs | 4 | ||||
| -rw-r--r-- | src/libstd/net/ip.rs | 83 | ||||
| -rw-r--r-- | src/libstd/net/tcp.rs | 12 | ||||
| -rw-r--r-- | src/libstd/panic.rs | 6 | ||||
| -rw-r--r-- | src/libstd/path.rs | 125 | ||||
| -rw-r--r-- | src/libstd/sync/mpsc/select.rs | 4 | ||||
| -rw-r--r-- | src/libstd/sync/mutex.rs | 14 | ||||
| -rw-r--r-- | src/libstd/sync/once.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sync/rwlock.rs | 26 | ||||
| -rw-r--r-- | src/libstd/sys_common/bytestring.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys_common/mutex.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys_common/remutex.rs | 8 |
24 files changed, 321 insertions, 194 deletions
diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index beecfb1aa29..a82b9498074 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -1641,7 +1641,7 @@ impl<K, V, S> Default for HashMap<K, V, S> } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, K, Q: ?Sized, V, S> Index<&'a Q> for HashMap<K, V, S> +impl<K, Q: ?Sized, V, S> Index<&Q> for HashMap<K, V, S> where K: Eq + Hash + Borrow<Q>, Q: Eq + Hash, S: BuildHasher @@ -1673,14 +1673,14 @@ pub struct Iter<'a, K: 'a, V: 'a> { // FIXME(#26925) Remove in favor of `#[derive(Clone)]` #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, K, V> Clone for Iter<'a, K, V> { - fn clone(&self) -> Iter<'a, K, V> { +impl<K, V> Clone for Iter<'_, K, V> { + fn clone(&self) -> Self { Iter { inner: self.inner.clone() } } } #[stable(feature = "std_debug", since = "1.16.0")] -impl<'a, K: Debug, V: Debug> fmt::Debug for Iter<'a, K, V> { +impl<K: Debug, V: Debug> fmt::Debug for Iter<'_, K, V> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_list() .entries(self.clone()) @@ -1726,14 +1726,14 @@ pub struct Keys<'a, K: 'a, V: 'a> { // FIXME(#26925) Remove in favor of `#[derive(Clone)]` #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, K, V> Clone for Keys<'a, K, V> { - fn clone(&self) -> Keys<'a, K, V> { +impl<K, V> Clone for Keys<'_, K, V> { + fn clone(&self) -> Self { Keys { inner: self.inner.clone() } } } #[stable(feature = "std_debug", since = "1.16.0")] -impl<'a, K: Debug, V> fmt::Debug for Keys<'a, K, V> { +impl<K: Debug, V> fmt::Debug for Keys<'_, K, V> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_list() .entries(self.clone()) @@ -1755,14 +1755,14 @@ pub struct Values<'a, K: 'a, V: 'a> { // FIXME(#26925) Remove in favor of `#[derive(Clone)]` #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, K, V> Clone for Values<'a, K, V> { - fn clone(&self) -> Values<'a, K, V> { +impl<K, V> Clone for Values<'_, K, V> { + fn clone(&self) -> Self { Values { inner: self.inner.clone() } } } #[stable(feature = "std_debug", since = "1.16.0")] -impl<'a, K, V: Debug> fmt::Debug for Values<'a, K, V> { +impl<K, V: Debug> fmt::Debug for Values<'_, K, V> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_list() .entries(self.clone()) @@ -2241,7 +2241,7 @@ impl<'a, K, V, S> RawVacantEntryMut<'a, K, V, S> { } #[unstable(feature = "hash_raw_entry", issue = "56167")] -impl<'a, K, V, S> Debug for RawEntryBuilderMut<'a, K, V, S> { +impl<K, V, S> Debug for RawEntryBuilderMut<'_, K, V, S> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("RawEntryBuilder") .finish() @@ -2249,7 +2249,7 @@ impl<'a, K, V, S> Debug for RawEntryBuilderMut<'a, K, V, S> { } #[unstable(feature = "hash_raw_entry", issue = "56167")] -impl<'a, K: Debug, V: Debug, S> Debug for RawEntryMut<'a, K, V, S> { +impl<K: Debug, V: Debug, S> Debug for RawEntryMut<'_, K, V, S> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { RawEntryMut::Vacant(ref v) => { @@ -2267,7 +2267,7 @@ impl<'a, K: Debug, V: Debug, S> Debug for RawEntryMut<'a, K, V, S> { } #[unstable(feature = "hash_raw_entry", issue = "56167")] -impl<'a, K: Debug, V: Debug> Debug for RawOccupiedEntryMut<'a, K, V> { +impl<K: Debug, V: Debug> Debug for RawOccupiedEntryMut<'_, K, V> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("RawOccupiedEntryMut") .field("key", self.key()) @@ -2277,7 +2277,7 @@ impl<'a, K: Debug, V: Debug> Debug for RawOccupiedEntryMut<'a, K, V> { } #[unstable(feature = "hash_raw_entry", issue = "56167")] -impl<'a, K, V, S> Debug for RawVacantEntryMut<'a, K, V, S> { +impl<K, V, S> Debug for RawVacantEntryMut<'_, K, V, S> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("RawVacantEntryMut") .finish() @@ -2285,7 +2285,7 @@ impl<'a, K, V, S> Debug for RawVacantEntryMut<'a, K, V, S> { } #[unstable(feature = "hash_raw_entry", issue = "56167")] -impl<'a, K, V, S> Debug for RawEntryBuilder<'a, K, V, S> { +impl<K, V, S> Debug for RawEntryBuilder<'_, K, V, S> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("RawEntryBuilder") .finish() @@ -2312,7 +2312,7 @@ pub enum Entry<'a, K: 'a, V: 'a> { } #[stable(feature= "debug_hash_map", since = "1.12.0")] -impl<'a, K: 'a + Debug, V: 'a + Debug> Debug for Entry<'a, K, V> { +impl<K: Debug, V: Debug> Debug for Entry<'_, K, V> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { Vacant(ref v) => { @@ -2340,7 +2340,7 @@ pub struct OccupiedEntry<'a, K: 'a, V: 'a> { } #[stable(feature= "debug_hash_map", since = "1.12.0")] -impl<'a, K: 'a + Debug, V: 'a + Debug> Debug for OccupiedEntry<'a, K, V> { +impl<K: Debug, V: Debug> Debug for OccupiedEntry<'_, K, V> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("OccupiedEntry") .field("key", self.key()) @@ -2361,7 +2361,7 @@ pub struct VacantEntry<'a, K: 'a, V: 'a> { } #[stable(feature= "debug_hash_map", since = "1.12.0")] -impl<'a, K: 'a + Debug, V: 'a> Debug for VacantEntry<'a, K, V> { +impl<K: Debug, V> Debug for VacantEntry<'_, K, V> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_tuple("VacantEntry") .field(self.key()) @@ -2448,7 +2448,7 @@ impl<'a, K, V> Iterator for Iter<'a, K, V> { } } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, K, V> ExactSizeIterator for Iter<'a, K, V> { +impl<K, V> ExactSizeIterator for Iter<'_, K, V> { #[inline] fn len(&self) -> usize { self.inner.len() @@ -2456,7 +2456,7 @@ impl<'a, K, V> ExactSizeIterator for Iter<'a, K, V> { } #[stable(feature = "fused", since = "1.26.0")] -impl<'a, K, V> FusedIterator for Iter<'a, K, V> {} +impl<K, V> FusedIterator for Iter<'_, K, V> {} #[stable(feature = "rust1", since = "1.0.0")] impl<'a, K, V> Iterator for IterMut<'a, K, V> { @@ -2472,17 +2472,17 @@ impl<'a, K, V> Iterator for IterMut<'a, K, V> { } } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, K, V> ExactSizeIterator for IterMut<'a, K, V> { +impl<K, V> ExactSizeIterator for IterMut<'_, K, V> { #[inline] fn len(&self) -> usize { self.inner.len() } } #[stable(feature = "fused", since = "1.26.0")] -impl<'a, K, V> FusedIterator for IterMut<'a, K, V> {} +impl<K, V> FusedIterator for IterMut<'_, K, V> {} #[stable(feature = "std_debug", since = "1.16.0")] -impl<'a, K, V> fmt::Debug for IterMut<'a, K, V> +impl<K, V> fmt::Debug for IterMut<'_, K, V> where K: fmt::Debug, V: fmt::Debug, { @@ -2539,14 +2539,14 @@ impl<'a, K, V> Iterator for Keys<'a, K, V> { } } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, K, V> ExactSizeIterator for Keys<'a, K, V> { +impl<K, V> ExactSizeIterator for Keys<'_, K, V> { #[inline] fn len(&self) -> usize { self.inner.len() } } #[stable(feature = "fused", since = "1.26.0")] -impl<'a, K, V> FusedIterator for Keys<'a, K, V> {} +impl<K, V> FusedIterator for Keys<'_, K, V> {} #[stable(feature = "rust1", since = "1.0.0")] impl<'a, K, V> Iterator for Values<'a, K, V> { @@ -2562,14 +2562,14 @@ impl<'a, K, V> Iterator for Values<'a, K, V> { } } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, K, V> ExactSizeIterator for Values<'a, K, V> { +impl<K, V> ExactSizeIterator for Values<'_, K, V> { #[inline] fn len(&self) -> usize { self.inner.len() } } #[stable(feature = "fused", since = "1.26.0")] -impl<'a, K, V> FusedIterator for Values<'a, K, V> {} +impl<K, V> FusedIterator for Values<'_, K, V> {} #[stable(feature = "map_values_mut", since = "1.10.0")] impl<'a, K, V> Iterator for ValuesMut<'a, K, V> { @@ -2585,17 +2585,17 @@ impl<'a, K, V> Iterator for ValuesMut<'a, K, V> { } } #[stable(feature = "map_values_mut", since = "1.10.0")] -impl<'a, K, V> ExactSizeIterator for ValuesMut<'a, K, V> { +impl<K, V> ExactSizeIterator for ValuesMut<'_, K, V> { #[inline] fn len(&self) -> usize { self.inner.len() } } #[stable(feature = "fused", since = "1.26.0")] -impl<'a, K, V> FusedIterator for ValuesMut<'a, K, V> {} +impl<K, V> FusedIterator for ValuesMut<'_, K, V> {} #[stable(feature = "std_debug", since = "1.16.0")] -impl<'a, K, V> fmt::Debug for ValuesMut<'a, K, V> +impl<K, V> fmt::Debug for ValuesMut<'_, K, V> where K: fmt::Debug, V: fmt::Debug, { @@ -2620,17 +2620,17 @@ impl<'a, K, V> Iterator for Drain<'a, K, V> { } } #[stable(feature = "drain", since = "1.6.0")] -impl<'a, K, V> ExactSizeIterator for Drain<'a, K, V> { +impl<K, V> ExactSizeIterator for Drain<'_, K, V> { #[inline] fn len(&self) -> usize { self.inner.len() } } #[stable(feature = "fused", since = "1.26.0")] -impl<'a, K, V> FusedIterator for Drain<'a, K, V> {} +impl<K, V> FusedIterator for Drain<'_, K, V> {} #[stable(feature = "std_debug", since = "1.16.0")] -impl<'a, K, V> fmt::Debug for Drain<'a, K, V> +impl<K, V> fmt::Debug for Drain<'_, K, V> where K: fmt::Debug, V: fmt::Debug, { diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index 92e63df7c68..bfd36a84563 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -1112,8 +1112,8 @@ impl<T, S> IntoIterator for HashSet<T, S> } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, K> Clone for Iter<'a, K> { - fn clone(&self) -> Iter<'a, K> { +impl<K> Clone for Iter<'_, K> { + fn clone(&self) -> Self { Iter { iter: self.iter.clone() } } } @@ -1129,16 +1129,16 @@ impl<'a, K> Iterator for Iter<'a, K> { } } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, K> ExactSizeIterator for Iter<'a, K> { +impl<K> ExactSizeIterator for Iter<'_, K> { fn len(&self) -> usize { self.iter.len() } } #[stable(feature = "fused", since = "1.26.0")] -impl<'a, K> FusedIterator for Iter<'a, K> {} +impl<K> FusedIterator for Iter<'_, K> {} #[stable(feature = "std_debug", since = "1.16.0")] -impl<'a, K: fmt::Debug> fmt::Debug for Iter<'a, K> { +impl<K: fmt::Debug> fmt::Debug for Iter<'_, K> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_list().entries(self.clone()).finish() } @@ -1187,16 +1187,16 @@ impl<'a, K> Iterator for Drain<'a, K> { } } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, K> ExactSizeIterator for Drain<'a, K> { +impl<K> ExactSizeIterator for Drain<'_, K> { fn len(&self) -> usize { self.iter.len() } } #[stable(feature = "fused", since = "1.26.0")] -impl<'a, K> FusedIterator for Drain<'a, K> {} +impl<K> FusedIterator for Drain<'_, K> {} #[stable(feature = "std_debug", since = "1.16.0")] -impl<'a, K: fmt::Debug> fmt::Debug for Drain<'a, K> { +impl<K: fmt::Debug> fmt::Debug for Drain<'_, K> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let entries_iter = self.iter .inner @@ -1207,8 +1207,8 @@ impl<'a, K: fmt::Debug> fmt::Debug for Drain<'a, K> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T, S> Clone for Intersection<'a, T, S> { - fn clone(&self) -> Intersection<'a, T, S> { +impl<T, S> Clone for Intersection<'_, T, S> { + fn clone(&self) -> Self { Intersection { iter: self.iter.clone(), ..*self } } } @@ -1236,7 +1236,7 @@ impl<'a, T, S> Iterator for Intersection<'a, T, S> } #[stable(feature = "std_debug", since = "1.16.0")] -impl<'a, T, S> fmt::Debug for Intersection<'a, T, S> +impl<T, S> fmt::Debug for Intersection<'_, T, S> where T: fmt::Debug + Eq + Hash, S: BuildHasher { @@ -1246,15 +1246,15 @@ impl<'a, T, S> fmt::Debug for Intersection<'a, T, S> } #[stable(feature = "fused", since = "1.26.0")] -impl<'a, T, S> FusedIterator for Intersection<'a, T, S> +impl<T, S> FusedIterator for Intersection<'_, T, S> where T: Eq + Hash, S: BuildHasher { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T, S> Clone for Difference<'a, T, S> { - fn clone(&self) -> Difference<'a, T, S> { +impl<T, S> Clone for Difference<'_, T, S> { + fn clone(&self) -> Self { Difference { iter: self.iter.clone(), ..*self } } } @@ -1282,14 +1282,14 @@ impl<'a, T, S> Iterator for Difference<'a, T, S> } #[stable(feature = "fused", since = "1.26.0")] -impl<'a, T, S> FusedIterator for Difference<'a, T, S> +impl<T, S> FusedIterator for Difference<'_, T, S> where T: Eq + Hash, S: BuildHasher { } #[stable(feature = "std_debug", since = "1.16.0")] -impl<'a, T, S> fmt::Debug for Difference<'a, T, S> +impl<T, S> fmt::Debug for Difference<'_, T, S> where T: fmt::Debug + Eq + Hash, S: BuildHasher { @@ -1299,8 +1299,8 @@ impl<'a, T, S> fmt::Debug for Difference<'a, T, S> } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T, S> Clone for SymmetricDifference<'a, T, S> { - fn clone(&self) -> SymmetricDifference<'a, T, S> { +impl<T, S> Clone for SymmetricDifference<'_, T, S> { + fn clone(&self) -> Self { SymmetricDifference { iter: self.iter.clone() } } } @@ -1321,14 +1321,14 @@ impl<'a, T, S> Iterator for SymmetricDifference<'a, T, S> } #[stable(feature = "fused", since = "1.26.0")] -impl<'a, T, S> FusedIterator for SymmetricDifference<'a, T, S> +impl<T, S> FusedIterator for SymmetricDifference<'_, T, S> where T: Eq + Hash, S: BuildHasher { } #[stable(feature = "std_debug", since = "1.16.0")] -impl<'a, T, S> fmt::Debug for SymmetricDifference<'a, T, S> +impl<T, S> fmt::Debug for SymmetricDifference<'_, T, S> where T: fmt::Debug + Eq + Hash, S: BuildHasher { @@ -1338,21 +1338,21 @@ impl<'a, T, S> fmt::Debug for SymmetricDifference<'a, T, S> } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T, S> Clone for Union<'a, T, S> { - fn clone(&self) -> Union<'a, T, S> { +impl<T, S> Clone for Union<'_, T, S> { + fn clone(&self) -> Self { Union { iter: self.iter.clone() } } } #[stable(feature = "fused", since = "1.26.0")] -impl<'a, T, S> FusedIterator for Union<'a, T, S> +impl<T, S> FusedIterator for Union<'_, T, S> where T: Eq + Hash, S: BuildHasher { } #[stable(feature = "std_debug", since = "1.16.0")] -impl<'a, T, S> fmt::Debug for Union<'a, T, S> +impl<T, S> fmt::Debug for Union<'_, T, S> where T: fmt::Debug + Eq + Hash, S: BuildHasher { diff --git a/src/libstd/collections/hash/table.rs b/src/libstd/collections/hash/table.rs index 9446a80a55c..865431252ac 100644 --- a/src/libstd/collections/hash/table.rs +++ b/src/libstd/collections/hash/table.rs @@ -296,7 +296,7 @@ pub trait Put<K, V> { } -impl<'t, K, V> Put<K, V> for &'t mut RawTable<K, V> { +impl<K, V> Put<K, V> for &mut RawTable<K, V> { unsafe fn borrow_table_mut(&mut self) -> &mut RawTable<K, V> { *self } @@ -865,8 +865,8 @@ struct RawBuckets<'a, K, V> { } // FIXME(#26925) Remove in favor of `#[derive(Clone)]` -impl<'a, K, V> Clone for RawBuckets<'a, K, V> { - fn clone(&self) -> RawBuckets<'a, K, V> { +impl<K, V> Clone for RawBuckets<'_, K, V> { + fn clone(&self) -> Self { RawBuckets { raw: self.raw, elems_left: self.elems_left, @@ -901,7 +901,7 @@ impl<'a, K, V> Iterator for RawBuckets<'a, K, V> { } } -impl<'a, K, V> ExactSizeIterator for RawBuckets<'a, K, V> { +impl<K, V> ExactSizeIterator for RawBuckets<'_, K, V> { fn len(&self) -> usize { self.elems_left } @@ -912,12 +912,12 @@ pub struct Iter<'a, K: 'a, V: 'a> { iter: RawBuckets<'a, K, V>, } -unsafe impl<'a, K: Sync, V: Sync> Sync for Iter<'a, K, V> {} -unsafe impl<'a, K: Sync, V: Sync> Send for Iter<'a, K, V> {} +unsafe impl<K: Sync, V: Sync> Sync for Iter<'_, K, V> {} +unsafe impl<K: Sync, V: Sync> Send for Iter<'_, K, V> {} // FIXME(#26925) Remove in favor of `#[derive(Clone)]` -impl<'a, K, V> Clone for Iter<'a, K, V> { - fn clone(&self) -> Iter<'a, K, V> { +impl<K, V> Clone for Iter<'_, K, V> { + fn clone(&self) -> Self { Iter { iter: self.iter.clone(), } @@ -931,10 +931,10 @@ pub struct IterMut<'a, K: 'a, V: 'a> { _marker: marker::PhantomData<&'a mut V>, } -unsafe impl<'a, K: Sync, V: Sync> Sync for IterMut<'a, K, V> {} +unsafe impl<K: Sync, V: Sync> Sync for IterMut<'_, K, V> {} // Both K: Sync and K: Send are correct for IterMut's Send impl, // but Send is the more useful bound -unsafe impl<'a, K: Send, V: Send> Send for IterMut<'a, K, V> {} +unsafe impl<K: Send, V: Send> Send for IterMut<'_, K, V> {} impl<'a, K: 'a, V: 'a> IterMut<'a, K, V> { pub fn iter(&self) -> Iter<K, V> { @@ -968,8 +968,8 @@ pub struct Drain<'a, K: 'a, V: 'a> { marker: marker::PhantomData<&'a RawTable<K, V>>, } -unsafe impl<'a, K: Sync, V: Sync> Sync for Drain<'a, K, V> {} -unsafe impl<'a, K: Send, V: Send> Send for Drain<'a, K, V> {} +unsafe impl<K: Sync, V: Sync> Sync for Drain<'_, K, V> {} +unsafe impl<K: Send, V: Send> Send for Drain<'_, K, V> {} impl<'a, K, V> Drain<'a, K, V> { pub fn iter(&self) -> Iter<K, V> { @@ -994,7 +994,7 @@ impl<'a, K, V> Iterator for Iter<'a, K, V> { } } -impl<'a, K, V> ExactSizeIterator for Iter<'a, K, V> { +impl<K, V> ExactSizeIterator for Iter<'_, K, V> { fn len(&self) -> usize { self.iter.len() } @@ -1015,7 +1015,7 @@ impl<'a, K, V> Iterator for IterMut<'a, K, V> { } } -impl<'a, K, V> ExactSizeIterator for IterMut<'a, K, V> { +impl<K, V> ExactSizeIterator for IterMut<'_, K, V> { fn len(&self) -> usize { self.iter.len() } @@ -1064,13 +1064,13 @@ impl<'a, K, V> Iterator for Drain<'a, K, V> { } } -impl<'a, K, V> ExactSizeIterator for Drain<'a, K, V> { +impl<K, V> ExactSizeIterator for Drain<'_, K, V> { fn len(&self) -> usize { self.iter.len() } } -impl<'a, K: 'a, V: 'a> Drop for Drain<'a, K, V> { +impl<K, V> Drop for Drain<'_, K, V> { fn drop(&mut self) { self.for_each(drop); } diff --git a/src/libstd/env.rs b/src/libstd/env.rs index 1f3b264c414..543973ab991 100644 --- a/src/libstd/env.rs +++ b/src/libstd/env.rs @@ -399,7 +399,7 @@ impl<'a> Iterator for SplitPaths<'a> { } #[stable(feature = "std_debug", since = "1.16.0")] -impl<'a> fmt::Debug for SplitPaths<'a> { +impl fmt::Debug for SplitPaths<'_> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.pad("SplitPaths { .. }") } diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index caf490a0277..0ef72242827 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -659,8 +659,8 @@ impl fmt::Debug for CStr { } #[stable(feature = "cstr_default", since = "1.10.0")] -impl<'a> Default for &'a CStr { - fn default() -> &'a CStr { +impl Default for &CStr { + fn default() -> Self { const SLICE: &[c_char] = &[0]; unsafe { CStr::from_ptr(SLICE.as_ptr()) } } diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs index 7dbf15cdc90..81433832ffc 100644 --- a/src/libstd/ffi/os_str.rs +++ b/src/libstd/ffi/os_str.rs @@ -778,10 +778,10 @@ impl Default for Box<OsStr> { } #[stable(feature = "osstring_default", since = "1.9.0")] -impl<'a> Default for &'a OsStr { +impl Default for &OsStr { /// Creates an empty `OsStr`. #[inline] - fn default() -> &'a OsStr { + fn default() -> Self { OsStr::new("") } } diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index f1e8619fc8f..79b5686faac 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -254,10 +254,13 @@ fn initial_buffer_size(file: &File) -> usize { /// ``` #[stable(feature = "fs_read_write_bytes", since = "1.26.0")] pub fn read<P: AsRef<Path>>(path: P) -> io::Result<Vec<u8>> { - let mut file = File::open(path)?; - let mut bytes = Vec::with_capacity(initial_buffer_size(&file)); - file.read_to_end(&mut bytes)?; - Ok(bytes) + fn inner(path: &Path) -> io::Result<Vec<u8>> { + let mut file = File::open(path)?; + let mut bytes = Vec::with_capacity(initial_buffer_size(&file)); + file.read_to_end(&mut bytes)?; + Ok(bytes) + } + inner(path.as_ref()) } /// Read the entire contents of a file into a string. @@ -296,10 +299,13 @@ pub fn read<P: AsRef<Path>>(path: P) -> io::Result<Vec<u8>> { /// ``` #[stable(feature = "fs_read_write", since = "1.26.0")] pub fn read_to_string<P: AsRef<Path>>(path: P) -> io::Result<String> { - let mut file = File::open(path)?; - let mut string = String::with_capacity(initial_buffer_size(&file)); - file.read_to_string(&mut string)?; - Ok(string) + fn inner(path: &Path) -> io::Result<String> { + let mut file = File::open(path)?; + let mut string = String::with_capacity(initial_buffer_size(&file)); + file.read_to_string(&mut string)?; + Ok(string) + } + inner(path.as_ref()) } /// Write a slice as the entire contents of a file. @@ -326,7 +332,10 @@ pub fn read_to_string<P: AsRef<Path>>(path: P) -> io::Result<String> { /// ``` #[stable(feature = "fs_read_write_bytes", since = "1.26.0")] pub fn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> io::Result<()> { - File::create(path)?.write_all(contents.as_ref()) + fn inner(path: &Path, contents: &[u8]) -> io::Result<()> { + File::create(path)?.write_all(contents) + } + inner(path.as_ref(), contents.as_ref()) } impl File { @@ -618,7 +627,7 @@ impl Seek for File { } } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a> Read for &'a File { +impl Read for &File { fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { self.inner.read(buf) } @@ -629,14 +638,14 @@ impl<'a> Read for &'a File { } } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a> Write for &'a File { +impl Write for &File { fn write(&mut self, buf: &[u8]) -> io::Result<usize> { self.inner.write(buf) } fn flush(&mut self) -> io::Result<()> { self.inner.flush() } } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a> Seek for &'a File { +impl Seek for &File { fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> { self.inner.seek(pos) } diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index 0615cd59db4..0c1d155a916 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -1174,7 +1174,7 @@ mod tests { // Issue #32085 struct FailFlushWriter<'a>(&'a mut Vec<u8>); - impl<'a> Write for FailFlushWriter<'a> { + impl Write for FailFlushWriter<'_> { fn write(&mut self, buf: &[u8]) -> io::Result<usize> { self.0.extend_from_slice(buf); Ok(buf.len()) diff --git a/src/libstd/io/cursor.rs b/src/libstd/io/cursor.rs index b205f788838..758d8568672 100644 --- a/src/libstd/io/cursor.rs +++ b/src/libstd/io/cursor.rs @@ -279,7 +279,7 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec<u8>, buf: &[u8]) -> io::Result<usi } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a> Write for Cursor<&'a mut [u8]> { +impl Write for Cursor<&mut [u8]> { #[inline] fn write(&mut self, buf: &[u8]) -> io::Result<usize> { slice_write(&mut self.pos, self.inner, buf) @@ -288,7 +288,7 @@ impl<'a> Write for Cursor<&'a mut [u8]> { } #[stable(feature = "cursor_mut_vec", since = "1.25.0")] -impl<'a> Write for Cursor<&'a mut Vec<u8>> { +impl Write for Cursor<&mut Vec<u8>> { fn write(&mut self, buf: &[u8]) -> io::Result<usize> { vec_write(&mut self.pos, self.inner, buf) } diff --git a/src/libstd/io/impls.rs b/src/libstd/io/impls.rs index ec75a87aec3..2577b284714 100644 --- a/src/libstd/io/impls.rs +++ b/src/libstd/io/impls.rs @@ -7,7 +7,7 @@ use mem; // Forwarding implementations #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, R: Read + ?Sized> Read for &'a mut R { +impl<R: Read + ?Sized> Read for &mut R { #[inline] fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { (**self).read(buf) @@ -34,7 +34,7 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { } } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, W: Write + ?Sized> Write for &'a mut W { +impl<W: Write + ?Sized> Write for &mut W { #[inline] fn write(&mut self, buf: &[u8]) -> io::Result<usize> { (**self).write(buf) } @@ -52,12 +52,12 @@ impl<'a, W: Write + ?Sized> Write for &'a mut W { } } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, S: Seek + ?Sized> Seek for &'a mut S { +impl<S: Seek + ?Sized> Seek for &mut S { #[inline] fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> { (**self).seek(pos) } } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { +impl<B: BufRead + ?Sized> BufRead for &mut B { #[inline] fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } @@ -152,7 +152,7 @@ impl<B: BufRead + ?Sized> BufRead for Box<B> { /// Note that reading updates the slice to point to the yet unread part. /// The slice will be empty when EOF is reached. #[stable(feature = "rust1", since = "1.0.0")] -impl<'a> Read for &'a [u8] { +impl Read for &[u8] { #[inline] fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { let amt = cmp::min(buf.len(), self.len()); @@ -207,7 +207,7 @@ impl<'a> Read for &'a [u8] { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a> BufRead for &'a [u8] { +impl BufRead for &[u8] { #[inline] fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } @@ -221,7 +221,7 @@ impl<'a> BufRead for &'a [u8] { /// Note that writing updates the slice to point to the yet unwritten part. /// The slice will be empty when it has been completely overwritten. #[stable(feature = "rust1", since = "1.0.0")] -impl<'a> Write for &'a mut [u8] { +impl Write for &mut [u8] { #[inline] fn write(&mut self, data: &[u8]) -> io::Result<usize> { let amt = cmp::min(data.len(), self.len()); diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index c0570ae60a1..b634ea43e34 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -299,7 +299,7 @@ const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; struct Guard<'a> { buf: &'a mut Vec<u8>, len: usize } -impl<'a> Drop for Guard<'a> { +impl Drop for Guard<'_> { fn drop(&mut self) { unsafe { self.buf.set_len(self.len); } } @@ -1114,7 +1114,7 @@ pub trait Write { error: Result<()>, } - impl<'a, T: Write + ?Sized> fmt::Write for Adaptor<'a, T> { + impl<T: Write + ?Sized> fmt::Write for Adaptor<'_, T> { fn write_str(&mut self, s: &str) -> fmt::Result { match self.inner.write_all(s.as_bytes()) { Ok(()) => Ok(()), diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index 4068c0f9c7d..0324568e6fb 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -312,7 +312,7 @@ impl Read for Stdin { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a> Read for StdinLock<'a> { +impl Read for StdinLock<'_> { fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { self.inner.read(buf) } @@ -323,13 +323,13 @@ impl<'a> Read for StdinLock<'a> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a> BufRead for StdinLock<'a> { +impl BufRead for StdinLock<'_> { fn fill_buf(&mut self) -> io::Result<&[u8]> { self.inner.fill_buf() } fn consume(&mut self, n: usize) { self.inner.consume(n) } } #[stable(feature = "std_debug", since = "1.16.0")] -impl<'a> fmt::Debug for StdinLock<'a> { +impl fmt::Debug for StdinLock<'_> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.pad("StdinLock { .. }") } @@ -485,7 +485,7 @@ impl Write for Stdout { } } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a> Write for StdoutLock<'a> { +impl Write for StdoutLock<'_> { fn write(&mut self, buf: &[u8]) -> io::Result<usize> { self.inner.borrow_mut().write(buf) } @@ -495,7 +495,7 @@ impl<'a> Write for StdoutLock<'a> { } #[stable(feature = "std_debug", since = "1.16.0")] -impl<'a> fmt::Debug for StdoutLock<'a> { +impl fmt::Debug for StdoutLock<'_> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.pad("StdoutLock { .. }") } @@ -638,7 +638,7 @@ impl Write for Stderr { } } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a> Write for StderrLock<'a> { +impl Write for StderrLock<'_> { fn write(&mut self, buf: &[u8]) -> io::Result<usize> { self.inner.borrow_mut().write(buf) } @@ -648,7 +648,7 @@ impl<'a> Write for StderrLock<'a> { } #[stable(feature = "std_debug", since = "1.16.0")] -impl<'a> fmt::Debug for StderrLock<'a> { +impl fmt::Debug for StderrLock<'_> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.pad("StderrLock { .. }") } diff --git a/src/libstd/net/addr.rs b/src/libstd/net/addr.rs index 654ad64d97b..4b60ee8e6da 100644 --- a/src/libstd/net/addr.rs +++ b/src/libstd/net/addr.rs @@ -861,7 +861,7 @@ fn resolve_socket_addr(lh: LookupHost) -> io::Result<vec::IntoIter<SocketAddr>> } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a> ToSocketAddrs for (&'a str, u16) { +impl ToSocketAddrs for (&str, u16) { type Iter = vec::IntoIter<SocketAddr>; fn to_socket_addrs(&self) -> io::Result<vec::IntoIter<SocketAddr>> { let (host, port) = *self; @@ -904,7 +904,7 @@ impl<'a> ToSocketAddrs for &'a [SocketAddr] { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T: ToSocketAddrs + ?Sized> ToSocketAddrs for &'a T { +impl<T: ToSocketAddrs + ?Sized> ToSocketAddrs for &T { type Iter = T::Iter; fn to_socket_addrs(&self) -> io::Result<T::Iter> { (**self).to_socket_addrs() diff --git a/src/libstd/net/ip.rs b/src/libstd/net/ip.rs index d19cc482c15..c8561290168 100644 --- a/src/libstd/net/ip.rs +++ b/src/libstd/net/ip.rs @@ -329,6 +329,8 @@ impl Ipv4Addr { /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub const fn new(a: u8, b: u8, c: u8, d: u8) -> Ipv4Addr { + // FIXME: should just be u32::from_be_bytes([a, b, c, d]), + // once that method is no longer rustc_const_unstable Ipv4Addr { inner: c::in_addr { s_addr: u32::to_be( @@ -392,6 +394,7 @@ impl Ipv4Addr { /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn octets(&self) -> [u8; 4] { + // This returns the order we want because s_addr is stored in big-endian. self.inner.s_addr.to_ne_bytes() } @@ -618,9 +621,13 @@ impl Ipv4Addr { /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn to_ipv6_compatible(&self) -> Ipv6Addr { - Ipv6Addr::new(0, 0, 0, 0, 0, 0, - ((self.octets()[0] as u16) << 8) | self.octets()[1] as u16, - ((self.octets()[2] as u16) << 8) | self.octets()[3] as u16) + let octets = self.octets(); + Ipv6Addr::from([ + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + octets[0], octets[1], octets[2], octets[3], + ]) } /// Converts this address to an IPv4-mapped [IPv6 address]. @@ -639,9 +646,13 @@ impl Ipv4Addr { /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn to_ipv6_mapped(&self) -> Ipv6Addr { - Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, - ((self.octets()[0] as u16) << 8) | self.octets()[1] as u16, - ((self.octets()[2] as u16) << 8) | self.octets()[3] as u16) + let octets = self.octets(); + Ipv6Addr::from([ + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0xFF, 0xFF, + octets[0], octets[1], octets[2], octets[3], + ]) } } @@ -784,7 +795,7 @@ impl From<Ipv4Addr> for u32 { /// ``` fn from(ip: Ipv4Addr) -> u32 { let ip = ip.octets(); - ((ip[0] as u32) << 24) + ((ip[1] as u32) << 16) + ((ip[2] as u32) << 8) + (ip[3] as u32) + u32::from_be_bytes(ip) } } @@ -801,7 +812,7 @@ impl From<u32> for Ipv4Addr { /// assert_eq!(Ipv4Addr::new(13, 12, 11, 10), addr); /// ``` fn from(ip: u32) -> Ipv4Addr { - Ipv4Addr::new((ip >> 24) as u8, (ip >> 16) as u8, (ip >> 8) as u8, ip as u8) + Ipv4Addr::from(ip.to_be_bytes()) } } @@ -909,14 +920,14 @@ impl Ipv6Addr { pub fn segments(&self) -> [u16; 8] { let arr = &self.inner.s6_addr; [ - (arr[0] as u16) << 8 | (arr[1] as u16), - (arr[2] as u16) << 8 | (arr[3] as u16), - (arr[4] as u16) << 8 | (arr[5] as u16), - (arr[6] as u16) << 8 | (arr[7] as u16), - (arr[8] as u16) << 8 | (arr[9] as u16), - (arr[10] as u16) << 8 | (arr[11] as u16), - (arr[12] as u16) << 8 | (arr[13] as u16), - (arr[14] as u16) << 8 | (arr[15] as u16), + u16::from_be_bytes([arr[0], arr[1]]), + u16::from_be_bytes([arr[2], arr[3]]), + u16::from_be_bytes([arr[4], arr[5]]), + u16::from_be_bytes([arr[6], arr[7]]), + u16::from_be_bytes([arr[8], arr[9]]), + u16::from_be_bytes([arr[10], arr[11]]), + u16::from_be_bytes([arr[12], arr[13]]), + u16::from_be_bytes([arr[14], arr[15]]), ] } @@ -1382,21 +1393,43 @@ impl FromInner<c::in6_addr> for Ipv6Addr { #[stable(feature = "i128", since = "1.26.0")] impl From<Ipv6Addr> for u128 { + /// Convert an `Ipv6Addr` into a host byte order `u128`. + /// + /// # Examples + /// + /// ``` + /// use std::net::Ipv6Addr; + /// + /// let addr = Ipv6Addr::new( + /// 0x1020, 0x3040, 0x5060, 0x7080, + /// 0x90A0, 0xB0C0, 0xD0E0, 0xF00D, + /// ); + /// assert_eq!(0x102030405060708090A0B0C0D0E0F00D_u128, u128::from(addr)); + /// ``` fn from(ip: Ipv6Addr) -> u128 { - let ip = ip.segments(); - ((ip[0] as u128) << 112) + ((ip[1] as u128) << 96) + ((ip[2] as u128) << 80) + - ((ip[3] as u128) << 64) + ((ip[4] as u128) << 48) + ((ip[5] as u128) << 32) + - ((ip[6] as u128) << 16) + (ip[7] as u128) + let ip = ip.octets(); + u128::from_be_bytes(ip) } } #[stable(feature = "i128", since = "1.26.0")] impl From<u128> for Ipv6Addr { + /// Convert a host byte order `u128` into an `Ipv6Addr`. + /// + /// # Examples + /// + /// ``` + /// use std::net::Ipv6Addr; + /// + /// let addr = Ipv6Addr::from(0x102030405060708090A0B0C0D0E0F00D_u128); + /// assert_eq!( + /// Ipv6Addr::new( + /// 0x1020, 0x3040, 0x5060, 0x7080, + /// 0x90A0, 0xB0C0, 0xD0E0, 0xF00D, + /// ), + /// addr); + /// ``` fn from(ip: u128) -> Ipv6Addr { - Ipv6Addr::new( - (ip >> 112) as u16, (ip >> 96) as u16, (ip >> 80) as u16, - (ip >> 64) as u16, (ip >> 48) as u16, (ip >> 32) as u16, - (ip >> 16) as u16, ip as u16, - ) + Ipv6Addr::from(ip.to_be_bytes()) } } diff --git a/src/libstd/net/tcp.rs b/src/libstd/net/tcp.rs index c4b0cd0f17c..51bd76ae436 100644 --- a/src/libstd/net/tcp.rs +++ b/src/libstd/net/tcp.rs @@ -580,7 +580,7 @@ impl Write for TcpStream { fn flush(&mut self) -> io::Result<()> { Ok(()) } } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a> Read for &'a TcpStream { +impl Read for &TcpStream { fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { self.0.read(buf) } #[inline] @@ -589,7 +589,7 @@ impl<'a> Read for &'a TcpStream { } } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a> Write for &'a TcpStream { +impl Write for &TcpStream { fn write(&mut self, buf: &[u8]) -> io::Result<usize> { self.0.write(buf) } fn flush(&mut self) -> io::Result<()> { Ok(()) } } @@ -1187,9 +1187,13 @@ mod tests { #[test] fn double_bind() { each_ip(&mut |addr| { - let _listener = t!(TcpListener::bind(&addr)); + let listener1 = t!(TcpListener::bind(&addr)); match TcpListener::bind(&addr) { - Ok(..) => panic!(), + Ok(listener2) => panic!( + "This system (perhaps due to options set by TcpListener::bind) \ + permits double binding: {:?} and {:?}", + listener1, listener2 + ), Err(e) => { assert!(e.kind() == ErrorKind::ConnectionRefused || e.kind() == ErrorKind::Other || diff --git a/src/libstd/panic.rs b/src/libstd/panic.rs index 862fdf051cc..daeac7107a5 100644 --- a/src/libstd/panic.rs +++ b/src/libstd/panic.rs @@ -199,9 +199,9 @@ pub struct AssertUnwindSafe<T>( // * Our custom AssertUnwindSafe wrapper is indeed unwind safe #[stable(feature = "catch_unwind", since = "1.9.0")] -impl<'a, T: ?Sized> !UnwindSafe for &'a mut T {} +impl<T: ?Sized> !UnwindSafe for &mut T {} #[stable(feature = "catch_unwind", since = "1.9.0")] -impl<'a, T: RefUnwindSafe + ?Sized> UnwindSafe for &'a T {} +impl<T: RefUnwindSafe + ?Sized> UnwindSafe for &T {} #[stable(feature = "catch_unwind", since = "1.9.0")] impl<T: RefUnwindSafe + ?Sized> UnwindSafe for *const T {} #[stable(feature = "catch_unwind", since = "1.9.0")] @@ -320,7 +320,7 @@ impl<T: fmt::Debug> fmt::Debug for AssertUnwindSafe<T> { } #[unstable(feature = "futures_api", issue = "50547")] -impl<'a, F: Future> Future for AssertUnwindSafe<F> { +impl<F: Future> Future for AssertUnwindSafe<F> { type Output = F::Output; fn poll(self: Pin<&mut Self>, waker: &Waker) -> Poll<Self::Output> { diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 0a9796d1a9c..240b92a17db 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -457,14 +457,14 @@ impl<'a> cmp::PartialOrd for PrefixComponent<'a> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a> cmp::Ord for PrefixComponent<'a> { - fn cmp(&self, other: &PrefixComponent<'a>) -> cmp::Ordering { +impl cmp::Ord for PrefixComponent<'_> { + fn cmp(&self, other: &Self) -> cmp::Ordering { cmp::Ord::cmp(&self.parsed, &other.parsed) } } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a> Hash for PrefixComponent<'a> { +impl Hash for PrefixComponent<'_> { fn hash<H: Hasher>(&self, h: &mut H) { self.parsed.hash(h); } @@ -561,14 +561,14 @@ impl<'a> Component<'a> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a> AsRef<OsStr> for Component<'a> { +impl AsRef<OsStr> for Component<'_> { fn as_ref(&self) -> &OsStr { self.as_os_str() } } #[stable(feature = "path_component_asref", since = "1.25.0")] -impl<'a> AsRef<Path> for Component<'a> { +impl AsRef<Path> for Component<'_> { fn as_ref(&self) -> &Path { self.as_os_str().as_ref() } @@ -630,11 +630,11 @@ pub struct Iter<'a> { } #[stable(feature = "path_components_debug", since = "1.13.0")] -impl<'a> fmt::Debug for Components<'a> { +impl fmt::Debug for Components<'_> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { struct DebugHelper<'a>(&'a Path); - impl<'a> fmt::Debug for DebugHelper<'a> { + impl fmt::Debug for DebugHelper<'_> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_list() .entries(self.0.components()) @@ -814,25 +814,25 @@ impl<'a> Components<'a> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a> AsRef<Path> for Components<'a> { +impl AsRef<Path> for Components<'_> { fn as_ref(&self) -> &Path { self.as_path() } } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a> AsRef<OsStr> for Components<'a> { +impl AsRef<OsStr> for Components<'_> { fn as_ref(&self) -> &OsStr { self.as_path().as_os_str() } } #[stable(feature = "path_iter_debug", since = "1.13.0")] -impl<'a> fmt::Debug for Iter<'a> { +impl fmt::Debug for Iter<'_> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { struct DebugHelper<'a>(&'a Path); - impl<'a> fmt::Debug for DebugHelper<'a> { + impl fmt::Debug for DebugHelper<'_> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_list() .entries(self.0.iter()) @@ -867,14 +867,14 @@ impl<'a> Iter<'a> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a> AsRef<Path> for Iter<'a> { +impl AsRef<Path> for Iter<'_> { fn as_ref(&self) -> &Path { self.as_path() } } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a> AsRef<OsStr> for Iter<'a> { +impl AsRef<OsStr> for Iter<'_> { fn as_ref(&self) -> &OsStr { self.as_path().as_os_str() } @@ -897,7 +897,7 @@ impl<'a> DoubleEndedIterator for Iter<'a> { } #[stable(feature = "fused", since = "1.26.0")] -impl<'a> FusedIterator for Iter<'a> {} +impl FusedIterator for Iter<'_> {} #[stable(feature = "rust1", since = "1.0.0")] impl<'a> Iterator for Components<'a> { @@ -1000,7 +1000,7 @@ impl<'a> DoubleEndedIterator for Components<'a> { } #[stable(feature = "fused", since = "1.26.0")] -impl<'a> FusedIterator for Components<'a> {} +impl FusedIterator for Components<'_> {} #[stable(feature = "rust1", since = "1.0.0")] impl<'a> cmp::PartialEq for Components<'a> { @@ -1010,7 +1010,7 @@ impl<'a> cmp::PartialEq for Components<'a> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a> cmp::Eq for Components<'a> {} +impl cmp::Eq for Components<'_> {} #[stable(feature = "rust1", since = "1.0.0")] impl<'a> cmp::PartialOrd for Components<'a> { @@ -1020,8 +1020,8 @@ impl<'a> cmp::PartialOrd for Components<'a> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a> cmp::Ord for Components<'a> { - fn cmp(&self, other: &Components<'a>) -> cmp::Ordering { +impl cmp::Ord for Components<'_> { + fn cmp(&self, other: &Self) -> cmp::Ordering { Iterator::cmp(self.clone(), other.clone()) } } @@ -1063,7 +1063,7 @@ impl<'a> Iterator for Ancestors<'a> { } #[stable(feature = "path_ancestors", since = "1.28.0")] -impl<'a> FusedIterator for Ancestors<'a> {} +impl FusedIterator for Ancestors<'_> {} //////////////////////////////////////////////////////////////////////////////// // Basic types and traits @@ -1145,6 +1145,33 @@ impl PathBuf { PathBuf { inner: OsString::new() } } + /// Creates a new `PathBuf` with a given capacity used to create the + /// internal [`OsString`]. See [`with_capacity`] defined on [`OsString`]. + /// + /// # Examples + /// + /// ``` + /// #![feature(path_buf_capacity)] + /// use std::path::PathBuf; + /// + /// let mut path = PathBuf::with_capacity(10); + /// let capacity = path.capacity(); + /// + /// // This push is done without reallocating + /// path.push(r"C:\"); + /// + /// assert_eq!(capacity, path.capacity()); + /// ``` + /// + /// [`with_capacity`]: ../ffi/struct.OsString.html#method.with_capacity + /// [`OsString`]: ../ffi/struct.OsString.html + #[unstable(feature = "path_buf_capacity", issue = "58234")] + pub fn with_capacity(capacity: usize) -> PathBuf { + PathBuf { + inner: OsString::with_capacity(capacity) + } + } + /// Coerces to a [`Path`] slice. /// /// [`Path`]: struct.Path.html @@ -1373,6 +1400,60 @@ impl PathBuf { let rw = Box::into_raw(self.inner.into_boxed_os_str()) as *mut Path; unsafe { Box::from_raw(rw) } } + + /// Invokes [`capacity`] on the underlying instance of [`OsString`]. + /// + /// [`capacity`]: ../ffi/struct.OsString.html#method.capacity + /// [`OsString`]: ../ffi/struct.OsString.html + #[unstable(feature = "path_buf_capacity", issue = "58234")] + pub fn capacity(&self) -> usize { + self.inner.capacity() + } + + /// Invokes [`clear`] on the underlying instance of [`OsString`]. + /// + /// [`clear`]: ../ffi/struct.OsString.html#method.clear + /// [`OsString`]: ../ffi/struct.OsString.html + #[unstable(feature = "path_buf_capacity", issue = "58234")] + pub fn clear(&mut self) { + self.inner.clear() + } + + /// Invokes [`reserve`] on the underlying instance of [`OsString`]. + /// + /// [`reserve`]: ../ffi/struct.OsString.html#method.reserve + /// [`OsString`]: ../ffi/struct.OsString.html + #[unstable(feature = "path_buf_capacity", issue = "58234")] + pub fn reserve(&mut self, additional: usize) { + self.inner.reserve(additional) + } + + /// Invokes [`reserve_exact`] on the underlying instance of [`OsString`]. + /// + /// [`reserve_exact`]: ../ffi/struct.OsString.html#method.reserve_exact + /// [`OsString`]: ../ffi/struct.OsString.html + #[unstable(feature = "path_buf_capacity", issue = "58234")] + pub fn reserve_exact(&mut self, additional: usize) { + self.inner.reserve_exact(additional) + } + + /// Invokes [`shrink_to_fit`] on the underlying instance of [`OsString`]. + /// + /// [`shrink_to_fit`]: ../ffi/struct.OsString.html#method.shrink_to_fit + /// [`OsString`]: ../ffi/struct.OsString.html + #[unstable(feature = "path_buf_capacity", issue = "58234")] + pub fn shrink_to_fit(&mut self) { + self.inner.shrink_to_fit() + } + + /// Invokes [`shrink_to`] on the underlying instance of [`OsString`]. + /// + /// [`shrink_to`]: ../ffi/struct.OsString.html#method.shrink_to + /// [`OsString`]: ../ffi/struct.OsString.html + #[unstable(feature = "path_buf_capacity", issue = "58234")] + pub fn shrink_to(&mut self, min_capacity: usize) { + self.inner.shrink_to(min_capacity) + } } #[stable(feature = "box_from_path", since = "1.17.0")] @@ -2529,14 +2610,14 @@ pub struct Display<'a> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a> fmt::Debug for Display<'a> { +impl fmt::Debug for Display<'_> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Debug::fmt(&self.path, f) } } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a> fmt::Display for Display<'a> { +impl fmt::Display for Display<'_> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.path.inner.display(f) } @@ -2590,7 +2671,7 @@ impl AsRef<Path> for OsStr { } #[stable(feature = "cow_os_str_as_ref_path", since = "1.8.0")] -impl<'a> AsRef<Path> for Cow<'a, OsStr> { +impl AsRef<Path> for Cow<'_, OsStr> { fn as_ref(&self) -> &Path { Path::new(self) } diff --git a/src/libstd/sync/mpsc/select.rs b/src/libstd/sync/mpsc/select.rs index 8f6f9818d5c..8591b55dc58 100644 --- a/src/libstd/sync/mpsc/select.rs +++ b/src/libstd/sync/mpsc/select.rs @@ -321,7 +321,7 @@ impl Drop for Select { } } -impl<'rx, T: Send> Drop for Handle<'rx, T> { +impl<T: Send> Drop for Handle<'_, T> { fn drop(&mut self) { unsafe { self.remove() } } @@ -347,7 +347,7 @@ impl fmt::Debug for Select { } } -impl<'rx, T:Send+'rx> fmt::Debug for Handle<'rx, T> { +impl<T: Send> fmt::Debug for Handle<'_, T> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("Handle").finish() } diff --git a/src/libstd/sync/mutex.rs b/src/libstd/sync/mutex.rs index 340dca7ce73..954867911a0 100644 --- a/src/libstd/sync/mutex.rs +++ b/src/libstd/sync/mutex.rs @@ -150,9 +150,9 @@ pub struct MutexGuard<'a, T: ?Sized + 'a> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T: ?Sized> !Send for MutexGuard<'a, T> { } +impl<T: ?Sized> !Send for MutexGuard<'_, T> { } #[stable(feature = "mutexguard", since = "1.19.0")] -unsafe impl<'a, T: ?Sized + Sync> Sync for MutexGuard<'a, T> { } +unsafe impl<T: ?Sized + Sync> Sync for MutexGuard<'_, T> { } impl<T> Mutex<T> { /// Creates a new mutex in an unlocked state ready for use. @@ -421,7 +421,7 @@ impl<'mutex, T: ?Sized> MutexGuard<'mutex, T> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'mutex, T: ?Sized> Deref for MutexGuard<'mutex, T> { +impl<T: ?Sized> Deref for MutexGuard<'_, T> { type Target = T; fn deref(&self) -> &T { @@ -430,14 +430,14 @@ impl<'mutex, T: ?Sized> Deref for MutexGuard<'mutex, T> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'mutex, T: ?Sized> DerefMut for MutexGuard<'mutex, T> { +impl<T: ?Sized> DerefMut for MutexGuard<'_, T> { fn deref_mut(&mut self) -> &mut T { unsafe { &mut *self.__lock.data.get() } } } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T: ?Sized> Drop for MutexGuard<'a, T> { +impl<T: ?Sized> Drop for MutexGuard<'_, T> { #[inline] fn drop(&mut self) { unsafe { @@ -448,14 +448,14 @@ impl<'a, T: ?Sized> Drop for MutexGuard<'a, T> { } #[stable(feature = "std_debug", since = "1.16.0")] -impl<'a, T: ?Sized + fmt::Debug> fmt::Debug for MutexGuard<'a, T> { +impl<T: ?Sized + fmt::Debug> fmt::Debug for MutexGuard<'_, T> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Debug::fmt(&**self, f) } } #[stable(feature = "std_guard_impls", since = "1.20.0")] -impl<'a, T: ?Sized + fmt::Display> fmt::Display for MutexGuard<'a, T> { +impl<T: ?Sized + fmt::Display> fmt::Display for MutexGuard<'_, T> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { (**self).fmt(f) } diff --git a/src/libstd/sync/once.rs b/src/libstd/sync/once.rs index 656389789d7..e207d0170d7 100644 --- a/src/libstd/sync/once.rs +++ b/src/libstd/sync/once.rs @@ -436,7 +436,7 @@ impl fmt::Debug for Once { } } -impl<'a> Drop for Finish<'a> { +impl Drop for Finish<'_> { fn drop(&mut self) { // Swap out our state with however we finished. We should only ever see // an old state which was RUNNING. diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs index 730362e2ac8..7f3cb4f72c7 100644 --- a/src/libstd/sync/rwlock.rs +++ b/src/libstd/sync/rwlock.rs @@ -91,10 +91,10 @@ pub struct RwLockReadGuard<'a, T: ?Sized + 'a> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T: ?Sized> !Send for RwLockReadGuard<'a, T> {} +impl<T: ?Sized> !Send for RwLockReadGuard<'_, T> {} #[stable(feature = "rwlock_guard_sync", since = "1.23.0")] -unsafe impl<'a, T: ?Sized + Sync> Sync for RwLockReadGuard<'a, T> {} +unsafe impl<T: ?Sized + Sync> Sync for RwLockReadGuard<'_, T> {} /// RAII structure used to release the exclusive write access of a lock when /// dropped. @@ -113,10 +113,10 @@ pub struct RwLockWriteGuard<'a, T: ?Sized + 'a> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T: ?Sized> !Send for RwLockWriteGuard<'a, T> {} +impl<T: ?Sized> !Send for RwLockWriteGuard<'_, T> {} #[stable(feature = "rwlock_guard_sync", since = "1.23.0")] -unsafe impl<'a, T: ?Sized + Sync> Sync for RwLockWriteGuard<'a, T> {} +unsafe impl<T: ?Sized + Sync> Sync for RwLockWriteGuard<'_, T> {} impl<T> RwLock<T> { /// Creates a new instance of an `RwLock<T>` which is unlocked. @@ -480,7 +480,7 @@ impl<'rwlock, T: ?Sized> RwLockWriteGuard<'rwlock, T> { } #[stable(feature = "std_debug", since = "1.16.0")] -impl<'a, T: fmt::Debug> fmt::Debug for RwLockReadGuard<'a, T> { +impl<T: fmt::Debug> fmt::Debug for RwLockReadGuard<'_, T> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("RwLockReadGuard") .field("lock", &self.__lock) @@ -489,14 +489,14 @@ impl<'a, T: fmt::Debug> fmt::Debug for RwLockReadGuard<'a, T> { } #[stable(feature = "std_guard_impls", since = "1.20.0")] -impl<'a, T: ?Sized + fmt::Display> fmt::Display for RwLockReadGuard<'a, T> { +impl<T: ?Sized + fmt::Display> fmt::Display for RwLockReadGuard<'_, T> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { (**self).fmt(f) } } #[stable(feature = "std_debug", since = "1.16.0")] -impl<'a, T: fmt::Debug> fmt::Debug for RwLockWriteGuard<'a, T> { +impl<T: fmt::Debug> fmt::Debug for RwLockWriteGuard<'_, T> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("RwLockWriteGuard") .field("lock", &self.__lock) @@ -505,14 +505,14 @@ impl<'a, T: fmt::Debug> fmt::Debug for RwLockWriteGuard<'a, T> { } #[stable(feature = "std_guard_impls", since = "1.20.0")] -impl<'a, T: ?Sized + fmt::Display> fmt::Display for RwLockWriteGuard<'a, T> { +impl<T: ?Sized + fmt::Display> fmt::Display for RwLockWriteGuard<'_, T> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { (**self).fmt(f) } } #[stable(feature = "rust1", since = "1.0.0")] -impl<'rwlock, T: ?Sized> Deref for RwLockReadGuard<'rwlock, T> { +impl<T: ?Sized> Deref for RwLockReadGuard<'_, T> { type Target = T; fn deref(&self) -> &T { @@ -521,7 +521,7 @@ impl<'rwlock, T: ?Sized> Deref for RwLockReadGuard<'rwlock, T> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'rwlock, T: ?Sized> Deref for RwLockWriteGuard<'rwlock, T> { +impl<T: ?Sized> Deref for RwLockWriteGuard<'_, T> { type Target = T; fn deref(&self) -> &T { @@ -530,21 +530,21 @@ impl<'rwlock, T: ?Sized> Deref for RwLockWriteGuard<'rwlock, T> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'rwlock, T: ?Sized> DerefMut for RwLockWriteGuard<'rwlock, T> { +impl<T: ?Sized> DerefMut for RwLockWriteGuard<'_, T> { fn deref_mut(&mut self) -> &mut T { unsafe { &mut *self.__lock.data.get() } } } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T: ?Sized> Drop for RwLockReadGuard<'a, T> { +impl<T: ?Sized> Drop for RwLockReadGuard<'_, T> { fn drop(&mut self) { unsafe { self.__lock.inner.read_unlock(); } } } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T: ?Sized> Drop for RwLockWriteGuard<'a, T> { +impl<T: ?Sized> Drop for RwLockWriteGuard<'_, T> { fn drop(&mut self) { self.__lock.poison.done(&self.__poison); unsafe { self.__lock.inner.write_unlock(); } diff --git a/src/libstd/sys_common/bytestring.rs b/src/libstd/sys_common/bytestring.rs index df57fae4281..915c17374ca 100644 --- a/src/libstd/sys_common/bytestring.rs +++ b/src/libstd/sys_common/bytestring.rs @@ -31,7 +31,7 @@ mod tests { fn smoke() { struct Helper<'a>(&'a [u8]); - impl<'a> Debug for Helper<'a> { + impl Debug for Helper<'_> { fn fmt(&self, f: &mut Formatter) -> Result { debug_fmt_bytestring(self.0, f) } diff --git a/src/libstd/sys_common/mutex.rs b/src/libstd/sys_common/mutex.rs index 536f1c70db2..b47d8698c60 100644 --- a/src/libstd/sys_common/mutex.rs +++ b/src/libstd/sys_common/mutex.rs @@ -76,7 +76,7 @@ pub fn raw(mutex: &Mutex) -> &imp::Mutex { &mutex.0 } /// A simple RAII utility for the above Mutex without the poisoning semantics. pub struct MutexGuard<'a>(&'a imp::Mutex); -impl<'a> Drop for MutexGuard<'a> { +impl Drop for MutexGuard<'_> { #[inline] fn drop(&mut self) { unsafe { self.0.unlock(); } diff --git a/src/libstd/sys_common/remutex.rs b/src/libstd/sys_common/remutex.rs index 9ef24433f13..596e5d534c2 100644 --- a/src/libstd/sys_common/remutex.rs +++ b/src/libstd/sys_common/remutex.rs @@ -43,7 +43,7 @@ pub struct ReentrantMutexGuard<'a, T: 'a> { __poison: poison::Guard, } -impl<'a, T> !marker::Send for ReentrantMutexGuard<'a, T> {} +impl<T> !marker::Send for ReentrantMutexGuard<'_, T> {} impl<T> ReentrantMutex<T> { @@ -138,7 +138,7 @@ impl<'mutex, T> ReentrantMutexGuard<'mutex, T> { } } -impl<'mutex, T> Deref for ReentrantMutexGuard<'mutex, T> { +impl<T> Deref for ReentrantMutexGuard<'_, T> { type Target = T; fn deref(&self) -> &T { @@ -146,7 +146,7 @@ impl<'mutex, T> Deref for ReentrantMutexGuard<'mutex, T> { } } -impl<'a, T> Drop for ReentrantMutexGuard<'a, T> { +impl<T> Drop for ReentrantMutexGuard<'_, T> { #[inline] fn drop(&mut self) { unsafe { @@ -212,7 +212,7 @@ mod tests { } pub struct Answer<'a>(pub ReentrantMutexGuard<'a, RefCell<u32>>); - impl<'a> Drop for Answer<'a> { + impl Drop for Answer<'_> { fn drop(&mut self) { *self.0.borrow_mut() = 42; } |
